The Prophet (a.s.) was assured as to the homage of the Ansar and he trusted in their loyalty to him and their devotedness in defending the Islamic mission. Yathrib became inaccessible fort of Islam. Many believers emigrated to it and found protection, security, and comfort there. The Prophet (a.s.) decided to emigrate to it and this was one of the most important events in the history of Islam. It was the blessed beginning of the establishment of the Islamic state and the spread of Islam throughout the Arabia.
Worry of Quraysh
When the news of the Prophet’s intention to leave Mecca to Yathrib, which he would take as a center for his mission, reached the people of Quraysh, they got very worried and upset. They used to harm the Prophet (a.s.) with every means they could get at hand. They had home-arrested him in the defile and severely punished the believers who followed him. Therefore, they thought that if he left their country, he might come back to them with an army that they would be unable to stand against, and then he would avenge on them severely. Different thoughts came to their minds and they feared for their interests that the people of Yathrib might cut the ways of their trade to Sham. Anyhow, the Meccans counted the cost of the Prophet’s emigration to Yathrib and took many steps to prevent it.
The chiefs of Quraysh called each other to meet in Dar an-Nadwa which was a house of Qusayy bin Kilab that the people of Quraysh had taken as a place of consultation whenever they faced a problem. The meeting included Utbah, Shaybah, Abu Sufyan, Tu’mah bin Adiy, Jubayr bin Mut’im, al-Harith bin Aamir, an-Nadhr bin al-Harith, ibn al-Bukhturi, Zam’ah bin al-Aswad, Hakeem bin Hizam, Abu Jahl, Nabeeh and Munabbih sons of al-Hajjaj, Umayyah bin Khalaf, and others. Iblis joined the meeting in the form of an old man from Najd. One of them opened the meeting saying, “This man (Muhammad) has done as you already have seen. By Allah, we are not safe from his leaping on us with those who have followed him from other than us. Let you agree on one opinion toward him.”
Ibn al-Bukhturi suggested, “Tie him (the Prophet) with iron chains and confine him behind doors. See what had afflicted the poets like him before such as Zuhayr and an-Nabighah and others who died in this way. Thus, he shall meet the same fate.”
The attendants did not agree on this suggestion and they said, “Muhammad’s companions definitely will know about the place of his confinement. They will attack the place and set Muhammad free.”
Al-Aswad bin Rabee’ah al-Aamiry said, “We expel him from our country. When he leaves us, by Allah, we shall not mind wherever he goes or whatever he does. When he is away from us and we are free from him, we shall then repair our affairs and unity as they were…”
The old man of Najd refuted this suggestion saying, “No by Allah, this suggestion is not good for you. Do you not see his (the Prophet) nice speech and good reasoning and his prevailing over men’s hearts by what he says? By Allah, if you do that, you shall not be safe that he may live among a tribe of the Arabs and affect them by his sayings and speeches until they shall follow him. Then, he shall march with them until he shall defeat you in your country and subjugate you, and then he will do to you as he wants. So find an opinion other than this one…”
The attendants approved this saying and gave up al-Aswad’s suggestion. Then Abu Jahl bin Hisham addressed the men saying, “I have an opinion about him that I see you have not got to yet!”
They asked what it was and he said, “I see that we should take from every tribe a brave young man and we give each of them a sharp sword. They should together go and strike him as a strike of one man and kill him. Thus, we shall be relieved from him. If they do that, his blood (murder) shall be divided among all the tribes, and then Bani Abd Manaf (the Hashemites) shall be unable to fight against all their people…”
All the attendants approved and agreed on this opinion and said, “There is no (accepted) opinion other than this.”
The men, who would carry out this crime, were chosen and the time of the attack against the Prophet’s house was appointed, but the Divine Will disappointed them. (And they planned and Allah (also) planned, and Allah is the best of planners).
The Prophet leaves Mecca
Allah the Almighty instructed His messenger to leave Mecca and emigrate to Yathrib. Allah informed the Prophet (a.s.) of the plot of the polytheists to assassinate him.
On that night, the chosen men surrounded the Prophet’s house waiting for the dawn to let their swords eat the Prophet’s flesh. The people of Quraysh wanted to support their idols and recover their position among the Arabs by getting rid of the messenger of Allah (a.s.).
Imam Ali sleeps in the Prophet’s bed
The Prophet (a.s.) informed Imam Ali (a.s.) about what Quraysh had plotted and he asked him to put on his (the Prophet) green garment and sleep in his (the Prophet) bed that night to make those villains believe that he was the Prophet (a.s.), and thus the Prophet (a.s.) would be safe from killing. Imam Ali (a.s.) received the Prophet’s order with delight and pleasure. He was very happy to be a sacrifice for the messenger of Allah (a.s.).
The Prophet (a.s.) went out of his house. He took a handful of earth and threw it on the men of Quraysh and said, ‘How ugly, mean faces!’
He went on while reciting, (And We have made before them a barrier and a barrier behind them, then We have covered them over so that they do not see).
The sleeping of Imam Ali (a.s.) in the Prophet’s bed and sacrificing himself for him was a shiny page from his sacred jihad. Allah has revealed about him, (And among people is he who sells himself to seek the pleasure of Allah).
Historians mention, “Allah the Almighty vied in glory with Imam Ali (a.s.) before His angels. He revealed to Gabriel and Michael, ‘I have made you as brothers and made the old of one of you longer than the other. Which of you prefer his friend to himself in life?’ Each of them preferred himself to his friend. Allah revealed to them, ‘Would you not be like Ali bin Abi Talib? I have made him as a brother to Muhammad and he slept in his (Muhammad) bed sacrificing him by his self and preferring him to himself in life. Go, you both, down to the earth and protect him from his enemy.’ They came down to the earth. Gabriel was at the head of Ali and Michael at his feet while saying, ‘Who is like you O Ali bin Abi Talib! Allah prides Himself on you before the angels.’ Allah then revealed to His messenger while he was moving towards Medina (Yathrib) this verse about Ali, (And among people is he who sells himself to seek the pleasure of Allah).”
When the light of morning came, the men attacked Imam Ali (a.s.) thinking that he was the Prophet (a.s.). Imam Ali (a.s.) drew his sword towards them and they were terribly surprised. They shouted at him, “Where is Muhammad?”
He said to them, “Have you made me a guard on him?”
They retreated taking with them disappointment and loss whereas the Prophet (a.s.) had slipped away safely. While he was moving toward Medina, the Prophet (a.s.) supplicated Allah with this supplication,
“Praise be to Allah Who created me when I was nothing. O Allah, assist me in the terror of life, troubles of time, and disasters of nights and days!
O Allah, accompany me in my travel, be my successor to my family, bless what You have endow on me, make me submit to You, affirm me with my good morals, make me, my Lord, love You, and do not make me in need of people!
O Lord of the disabled! You are my Lord. I seek refuge by Your Honorable Face to which the heavens and the earth have shone, and darks have been removed, and the affairs of the firsts and the lasts have been repaired, not to afflict on me Your anger or send down on me Your wrath. I seek Your protection from the disappearance of Your blessing, from Your sudden punishment, the change of Your soundness (to me), and from all Your wrath. I beseech You as possible I can, and there is no power and might save in You.”
The Prophet with Suraqah
Quraysh offered one hundred camels for whoever would arrest the Prophet (a.s.) during his journey to Yathrib. Suraqah bin Malik set out looking for the Prophet (a.s.). When Suraqah found the Prophet (a.s.), the Prophet prayed Allah, “O Allah, save me from the evil of Suraqah bin Malik with whatever You will.” Allah responded to his supplication and the legs of Suraqa’s horse sank in the ground. Suraqa said to the Prophet (a.s.), “What has happened to my horse is from you. Pray Allah to release my horse. By my life, if no good from me came to you, no evil from me shall come to you.” The Prophet (a.s.) prayed Allah and Suraqa’s horse was released. However, Suraqa did not refrain and he chased the Prophet (a.s.) again. His horse’s legs sank in the ground, and he asked the Prophet (a.s.) again to pray Allah for him. This happened three times. In the third time, Suraqa said to the Prophet (a.s.), “O Muhammad, these are my camels. They are before you and my servant is with them. If you need a mount or milk, you can take from him. This is an arrow from my quiver as a sign, and I will go back to confuse those who will chase you.”
The Prophet (a.s.) said to him, “We are in no need of what you have.”
The Prophet (a.s.) headed for Yathrib after he was saved from the villains of Quraysh. Abu Bakr was with him. They remained in the cave of Thour for three days. Allah the Almighty sent a couple of pigeons to lay eggs at the bottom of the opening of the cave and a spider to spin its cobweb on the opening. The men of Quraysh wasted no minute in chasing the Prophet (a.s.). They, headed by Suraqa bin Malik who was an expert tracer, reached the cave. When Suraqa saw the eggs of the pigeons and cobweb, he said to his companions that if anyone entered the cave the eggs and the cobweb would be damaged. The Prophet (a.s.) was seeing and hearing them. He prayed Allah saying, “O Allah, blind their sights!”
Allah blinded their sights and they could not find the Prophet (a.s.). Abu Bakr was afraid, but the Prophet (a.s.) calmed him down and said to him, “Do not be afraid, for Allah is with us.”
Then, this verse was revealed to the Prophet (a.s.), (If you will not aid him, Allah certainly aided him when those who disbelieved expelled him, he being the second of the two, when they were both in the cave, when he said to his companion: Grieve not, surely Allah is with us. So Allah sent down His tranquility upon him and strengthened him with hosts which you did not see, and made lowest the word of those who disbelieved; and the word of Allah, that is the highest; and Allah is Mighty, Wise).
When the men of Quraysh was desperate of finding the messenger of Allah, they went back to Mecca. The Prophet (a.s.) had hired two camels; one for him and the other for Abu Bakr. When the men of Quraysh no longer looked for the Prophet (a.s.), the two camels were brought to him. He and Abu Bakr mounted the camels and set out toward Yathrib.
Yathrib receives the Prophet
The news got to the people of Yathrib that the messenger of Allah had emigrated towards them. The masses longingly hurried to receive and welcome him. The women began chanting:
“The dawn has come to us
from the defiles of al-Wada’.
Gratefulness has become obligatory on us,
Whenever an inviter invites for Allah.”
Masses of people crowded in the streets crying out; ‘Muhammad has come’, ‘the messenger of Allah has come’, ‘Allahu akbar’. The public, under a halo of ‘Allahu akbar’ gathered together to receive and welcome the Savior who had been sent by Allah to save mankind. It was a memorable day that Yathrib had never seen like before. On the other hand, the Prophet (a.s.) felt delight and satisfaction by that great welcome.
The chiefs of the tribes surrounded the Prophet (a.s.) and each of them looked forward to have the honor of hosting the Prophet (a.s.) in his house. The Prophet (a.s.) thanked them all and said that his she-camel had been ordered (by Allah) to stop at the place that Allah the Almighty had chosen. The she-camel walked being followed by the crowds of people until it reached the house of Abu Ayyoob Khalid bin Zayd. It knelt down and the Prophet (a.s.) dismounted. Abu Ayyoob received the Prophet (a.s.) with all regard and honoring, and he considered that as one of Allah’s favors and blessings on him.
The notables, the chiefs, and all classes of Yathrib came to the Prophet (a.s.) welcoming and assuring him of their protection to him and defending his religion. The Prophet (a.s.) thanked and said to them, “You are the most beloved people to me.” He repeated this three times.
The Prophet (a.s.) lived in the ground-floor and Abu Ayyoob lived in the upper floor. Abu Ayyoob felt embraced and very distressed. He said to the Prophet, “I never ascend a roof that you are under it!” It was from Abu Ayyoob’s great politeness, and so the Prophet (a.s.) turned to live in the upper floor.
Abu Ayyoub and his wife served food and offered it to the Prophet (a.s.). They eagerly ate whatever remained in the dish that they might be blessed by it.
Then, the Prophet (a.s.) built a house near the mosque with adobes and roofed it with palm trucks and fronds.
The population of Yathrib
The Prophet (a.s.) asked Huthayfah bin al-Yaman to record the number of Muslims (in Yathrib), and Huthayfah wrote down to him one thousand and five hundred men.
Most of the inhabitants of Yathrib, which the Prophet (a.s.) took as the capital of his state, responded to embrace Islam. They entered violent wars against the powerful forces of the enemies of Islam that were armed with the most modern arms of that time whereas the Muslim army had no weapons except strong faith and fixed beliefs. Nevertheless, Muslims could defeat the powerful enemies and Allah assisted His religion and honored His messenger, and soon the light of Islam moved to all directions.
It is worth mentioning that the inhabitants of Medina were not the same in their beliefs. There were true believers, hesitant Muslims, and a group of hypocrites who were apparently Muslims whereas their hearts were full of disbelief and grudge against Islam. In Medina, as well, there were the Jews who were the most dangerous enemies to Islam in the past (and are still so in the present). No plot was prepared against Islam except that they supplied it with arms and money. When that was clear to the Prophet (a.s.), he waged wars against them and warned Muslims against their evils. The last one of the Prophet’s instructions was to expel the Jews from the Arabia as al-Waqidi has mentioned.
Anyhow, most of the inhabitants of Medina were from the tribes of al-Aws and al-Khazraj. Many wars had broken out between them, but the Prophet (a.s.) put an end to their enmity and made them as brothers to each other.
When the Prophet (a.s.) came to Medina, he offered Friday Prayer and made this speech before Muslims:
“Praise be to Allah Whom I praise, beseech His assistance, seek His forgiveness, request His guidance, believe and do not disbelieve in Him, feud with whoever disbelieve in Him, and bear witness that there is no god but Allah alone with no associate to Him, and that Muhammad is His slave and messenger whom He has sent with guidance and the religion of truth, light, and admonition after a cessation of messengers, littleness of knowledge, deviation of people, elapse of time, approach to the Hour (Last Day), and nearness to the end. Whoever obeys Allah and His messenger is on the right way, and whoever disobeys them goes astray, neglect, and is deviant in absolute deviation.
I recommend you of being pious to Allah, for the best that which a Muslim should recommend a Muslim of is to enjoin him to be pious to Allah, so beware of what Allah has warned you against from Himself, and there is no better than this advice and no better than this reminding. It is piety to whoever follows it with fear and attention, and true assistance to what you intend from the affairs of the afterlife.
Whoever is true in that which is between him and Allah in secret and openness not intending by that except the Face of Allah shall be a (good) mention to him in his life and a provision to him after death when man is in need of what he has done afore, and whatever other than that he shall wish that between him and that (evil) there were a long duration of time; and Allah makes you to be cautious of (retribution from) Himself, and Allah is Compassionate to the servants.
By Him Who is truthful in His saying and has fulfilled His promise, there shall be no renege to that, for He the Great and Almighty says, (My word shall not be changed, nor am I in the least unjust to the servants).
Fear Allah as to your worldly life and afterlife in secret and openness, for He says, (and whoever fears Allah, He will remit from him his evil deeds and will enlarge his reward). And whoever fears Allah shall win a great winning; surely the fear of Allah safeguards against His aversion, safeguards against His punishment, and safeguards against His wrath. And surely the fear of Allah honors the faces, pleases the Lord, and exalts the rank.
Be careful and do not fall short of your duty to Allah. Allah has taught you His Book and made clear to you His path to know those who are true and those who are liars. So do good as Allah has done good to you, feud with His enemies, and strive in the way of Allah in the striving that is His right. He has chosen you and named you Muslims (that he who would perish might perish by clear proof, and he who would live might live by clear proof) and there is no power save in Allah. So increase the remembrance of Allah and work for that which is after death, for whoever repairs what is between him and Allah, Allah will suffice to him what is between him and people that is because Allah determines for people and they do not determine for Him, and He has authority over people and they do not have authority over Him. Allah is great and there is no power save in Allah, the High, the Great.”
The building of the mosque
After no long, the Prophet (a.s.) established the mosque (of the Prophet) to be a center for his government, a school for his teachings, and a place for his worship. The piece of land, which the Prophet (a.s.) wanted to build his mosque on, was called al-Mirbad. After asking about its owner, it was said to him that it belonged to Sahl and Suhayl sons of Amr. They were orphans secured by Mu’ath bin Afra’. After the owners of the land were satisfied, the Prophet (a.s.) built the mosque which was sixty cubits long and the same in wide. The Prophet (a.s.) himself was one of the workers who participated in the building of the mosque, and so was Imam Ali (a.s.). After establishing the mosque of the Prophet (a.s.) and his houses, Islam spread everywhere in Medina, and henceforth the great Islamic state was established.
 As-Seera an-Nabawiyyah by ibn Hisham, vol. 2 p. 125.
 As-Seera an-Nabawiyyah by ibn Hisham, vol. 2 p. 126.
 Al-Kamil fit-Tareekh, vol. 2 p. 28, As-Seera an-Nabawiyyah by ibn Hisham, vol. 2 p. 126, Tareekh at-Tabari, vol. 2 p. 243.
 Qur'an, 36:9.
 Qur'an, 2:207.
 Usd al-Ghabah, vol. 4 p. 25, Noor al-Absar, p. 77, Tafsir ar-Razi, vol. 5 p. 223, Musnad of Ahmed bin Hanbal, vol. 1 p. 348, Tareekh Baghdad, vol. 13 p. 191, Mustadrak al-Hakim, vol. 3 p. 4, Tabaqat ibn Sa’d, vol. 8 p. 35.
 As-Seera an-Nabawiyyah by ibn Katheer, vol. 2 p. 234.
 Rawdhatul-Kafi, p. 263.
 It lies an hour-travel from Mecca.
 Qur'an, 9:40.
 A valley in Mecca.
 As-Seera an-Nabawiyyah by ibn Katheer, vol. 2 p. 269.
 As-Seera an-Nabawiyyah by Zayni Dahlan, vol. 1 p. 172.
 As-Seera an-Nabawiyyah by ibn Hisham, vol. 1 p. 495.
 As-Seera an-Nabawiyyah by ibn Katheer, vol. 2 p. 275.
 Ibid., p. 278.
 As-Seera an-Nabawiyyah by ibn Hisham, vol. 2 p. 144, As-Seera an-Nabawiyyah by ibn Katheer, vol. 2 p. 2 77.
 As-Seera an-Nabawiyyah by ibn Hisham, vol. 2 p. 141.
 Al-Eeman by ibn Mundah, p. 453, Sharh as-Sunnah, vol. 6 p. 288.
 Qur'an, 50:29.
 Qur'an, 65:5.
 Qur'an, 8:42.
 As-Seera an-Nabawiyyah by ibn Katheer, vol. 2 p. 299-301, Tareekh at-Tabari, vol. 2 p. 116,117.
source : http://www.maaref-foundation.com