The Prophet (S.A.W) informed Ali (A.S.) about the dangerous situation and his plan to migrate to Yasrib. He asked Ali (A.S.) if he would sleep in his (Prophet (S.A.W)s) bed covering himself with the Prophet (S.A.W)s green chaddor. It was a dangerous situation, the walls of the Prophet (S.A.W)s house were hardly seven feet high. Anybody could peep in and see whether the Prophet (S.A.W) was in the house or not. But when the Prophet (S.A.W) asked Ali (A.S.) if he would accept this danger to his life? Ali (A.S.) replied with a counter question, "If I sleep in your place, in your bed, will your life be saved?" "Yes." replied the Prophet (S.A.W), "Allah has promised me save passage" Ali (A.S.) thanked Allah and slept in the bed of the Prophet (S.A.W) covering himself with the Prophet (S.A.W)s green chaddor. The Prophet (S.A.W) left his house unobserved by the waiting assailants.
Commenting on the sacrifice of Ali (A.S.), Imam Gazali in his Tareekhe Khamees writes that it was for this occasion that revelation from Allah came, " Among the people are those who sell their lives to seek the satisfaction of Allah." [Vol.1, page 267] Qastalani in Mohabbe Ladeem says that Ali (A.S.) was the first person to sell his life [Vol.1, page 78].
During the night many stones and arrows were thrown on the bed of the Prophet (S.A.W) but Ali (A.S.) did not move. In the morning when the assailants jumped in and pulled the green chaddor they found Ali (A.S.) in the place of Mohammad (S.A.W). "Where is Mohammad?" they asked in anger. "What do I know? You did not give Mohammad to me," Ali (A.S.) replied. The assailants wanted to kill him, but when they saw Ali (A.S.) defiant and ready to fight they left him and went out in search of the Prophet (S.A.W).
This departure of the Prophet (S.A.W) from Mecca to Yasrib is called Hijrat. It took place on Thursday in the month of September 622 A.D. The Muslim era is named after this event. It was introduced by Umar Bin Khattab during his rule on the advice of Ali (A.S.). In those days the solar calendar of the Christians and the ancient calendar known as Aamul Feel were in vogue and people often got confused in recording the events.
Ali (A.S.) stayed in Mecca for three days fulfilling the task the Prophet (S.A.W) gave him. Specially the return of the goods and money, the people of Mecca had kept him for safe custody, and arranging the supply of food and water to the Prophet (S.A.W) who was staying in the caves of Hera on the outskirts of Mecca. Ali (A.S.) arranged for the food and Amir Bin Faheera carried it to the cave. As the Prophet (S.A.W) did not have any mounts with him nor any guide who could show him the way to Yasrib Ali (A.S.) purchased three camels from the people of Bahrain who were camping in Mecca and the services of Abdullah Bin Yarkat to show the way to Yasrib [Tafseer-e- Durre Mansoor, Vol. 3, page 240].
After completing the job Ali (A.S.) left Mecca in broad daylight with four ladies the Prophet (S.A.W) had asked him to bring. They were :-
(1) Fatema (S.A.) the Prophet (S.A.W)s daughter, (2) Fatema, Ali (A.S.)s mother, (3) Fatema, cousin of Ali (A.S.) and Mohammad (S.A.W) and daughter of Hamza, (4) Fatema, Ali (A.S.)s aunt. The Quraish sent eight men to stop Ali (A.S.) from taking these ladies with him, but Ali (A.S.) refused to part with them and fought with them killing one Junnah and driving the rest away. The journey to Madina was of ten days, and as Ali (A.S.) had only two camels with him on which the ladies of his household were sitting he walked the entire 280 miles on foot.
The Prophet (S.A.W) who had reached Quba (a village two miles before Yasrib) by then, was anxiously awaiting his arrival. The Prophet (S.A.W) received Ali (A.S.), embraced him and dressed his bleeding feet.
The Prophet (S.A.W) during his four day stay at Quba constructed the worlds first Mosque with the help of the local Muslims. He himself participated in the construction work, and carried stones and mud on his head. The Muslims while constructing the mosque recited, "Whosoever builds a Mosque and reads Quran is saved." After completing the Mosque the Prophet (S.A.W) and his followers offered their first prayer in it facing Jerusalem.
During the Prophet (S.A.W)s stay at Quba the strength of the Muslims grew constantly. People broke their idols and embraced Islam. The Prophet (S.A.W) then left for Yasrib with his entire group. Buraida Bin Al Hasseeb and his seventy men had just embraced Islam took the Prophet (S.A.W) in a procession.
The city of Yasrib was a collection of houses, castles, farms and gardens. All located in comparatively green lands. The inhabitants of this city belonged to the tribes of Aws and Khazraj the two branches of Azd clan, an idol worshipping community. Along with them lived Bani Quraizah, Bani Nazir and Bani Quinqaa, the Jewish tribes who had migrated from different places and settled here. The city of Yasrib like other cities of those days were ruled by oppression, tyranny and war. The tribes of Aws and Khazraj always fought among themselves and were bitter enemies of each other. But their enmity ended to some extent with the arrival of the Prophet (S.A.W) to Yasrib with his message of love, brotherhood and equality, kindness and sincerity, the blessings of Islam.