The Prophet (peace be upon him) was in Mecca when he was ordered to immigrate to Medinah. The following was revealed to him, {Say, ‘Oh Lord, make me enter a true entering and leave a true leaving, My Lord, make my entry sincere and faithful to the Truth, and make my leaving sincere and faithful to the Truth, and grant me, from Your Presence, supporting authority,’} and Qatadah explained, “Make my entry sincere refers to Medinah, and make my leaving sincere refers to the immigration from Mecca. And grant me, from Your Presence, supporting authority refers to the book of Allah, His religion and His limits (permissible and prohibited acts)” [The Beginning and the End by Ibn Katheer].
Allah (Glorified is He) wanted to rescue the Prophet (peace be upon him) and protect him. Therefore, Gibrael came down with revelation telling the Prophet about how the disbelievers had planned to harm him. Allah (Glorified is He) says, {When those who disbelieved were plotting against you to imprison you, kill you or expel you: they were plotting and Allah was plotting, but Allah is the Best of Plotters} [Surah Al-Infal: 30].
Gibrael ordered the Prophet (peace be upon him) not to sleep in his home that night. Therefore, the Prophet (peace be upon him) went to Abu Bakr to give him the good news that they will immigrate. Aisha (may Allah be pleased with her) told us about this, saying, <When permission was given for him (the Prophet) to leave to Medinah, he came to us unexpectedly at noon. When Abu Bakr was told about this, he said, ‘The Prophet does not come to us at such a time unless there is something important.’ When the Prophet (peace be upon him) entered, he said to Abu Bakr, ‘Tell those in your home to leave.’ Abu Bakr (may Allah be pleased with him) said, ‘Oh Prophet, only my two daughters (Aisha and Asma) are here.’ The Prophet (peace be upon him) said, ‘Do you not understand that I have been given permission to leave [to Medinah].’ Abu Bakr replied, ‘I want to accompany you, Oh Prophet.’ The Prophet (peace be upon him) said, ‘You will accompany me.’ Abu Bakr then said, ‘Oh Prophet, I have two camels which I have prepared for the journey, so take one of them.’ The Prophet (peace be upon him) said, ‘I will take it if I pay for it’ [related by Al-Bukhari].
The Prophet (peace be upon him) had ordered Ali ibn Abu Talib to sleep in the Prophet’s home that night. He also ordered him to give the trusts which the Prophet had to their owners; there was no one in Mecca who had some possession he was worried about but he would give it to the Prophet (peace be upon him) for safe keeping, due to the Prophet’s reputation of being truthful and trustworthy.
Ali (may Allah be pleased with him) stayed that night in the Prophet’s home, covered with the Prophet’s bedcover. And when the group of disbelievers of Quraysh gathered outside the Prophet’s home, they kept looking through a peephole in the Prophet’s door, watching him (Ali). The Prophet (peace be upon him) opened his door to stand before them, taking a handful of dust which he scattered over their heads while reciting Allah’s saying, {Ya Sin. By the Quran, full of wisdom, you are indeed one of the Messengers, on a straight path. (This is) The revelation of the Almighty, the Most Merciful, to warn a people whose forefathers were not warned, and so they are unaware} [Surah Yasin: 1 – 7], until he reached the ayah (verse of Quran), {I t makes no difference to them whether you warn them or do not warn them: they will not believe} [Surah Yasin: 10]. Then the Prophet (peace be upon him) left in front of them, although they did not notice him. Allah (Glorified is He) says about the state of these disbelievers, {And We shall raise a barrier in front of them and a barrier behind them, and cover them over so that they will not be able to see} [Yasin: 9].
The disbelievers kept waiting until a man passed by them and asked, “What are you waiting for?” they replied, “Muhammed.” He then said, “May you be fooled and lose. By Allah, he (the Prophet) walked past you, throwing dust on your heads!” They remarked, “By Allah, we did not see him!” They started to brush off the dust from their heads. When they entered the room, Ali stood up from the bed, so they asked him about the Prophet. Ali replied, “I do not know anything about him.” The Prophet (peace be upon him) had gone to Abu Bakr’s home and stayed the night there with him. The Prophet (peace be upon him) and Abu Bakr left and went to Thawr cave [At-Tabaqat Al-Kobra by Saad]. This is how the Prophet’s blessed journey of immigration from Mecca to Medinah started.