Migration to Madina:
In 622 CE, the leaders of the Quraish decided to martyr the Prophet (Peace Be Upon Him). For this purpose they developed a plan in which one man was chosen from each of the Quraish tribes and they were to attack the Prophet simultaneously, Thus the responsibility of shedding his blood would lie equally on all the clans, and no single clan whatsoever would then be held responsible for it.
By the order of All-Knowing God, angel Gabriel informed the Prophet (Peace Be Upon Him) of their wicked plan and conveyed him the message of God to leave Mecca immediately. The Prophet, after making arrangements to return the properties entrusted to him by several nonbelievers, left with a close friend Abu Bakr in the night he was to be assassinated. They went south of Mecca to a mountain cave of Thawr and after staying three nights they traveled north to Yathrib (Madina) about two hundred fifty miles from Mecca.
On his way to Madina the Prophet (Peace Be Upon Him) stayed with the tribe "Bani 'Amr bin 'Auf " for four days. He laid the foundation of "Quba Mosque" which has the honor to be the first mosque of Islam. This mosque is situated in the outskirts of Madina.
The news about the Prophet’s (Peace Be Upon Him) departure from Mecca had already spread fast and the Ansaar were eagerly expecting his arrival. At last, the Prophet (Peace Be Upon Him) arrived one day. More or less five hundred Ansaar rushed to pay their respects to the Prophet of God (Peace Be Upon Him); they requested him to enter the city, saying, "Ride on! Ye two are safe and we shall obey you!" When Prophet (Peace Be Upon Him) entered the city of Madina the people thronged in the way at their doors and windows and on the roofs of the houses to display warmth and happiness on his arrival. Madina appeared to be jubilant and beaming into a smile.
Everyone was wishing to take the honor of being his host. They were offering to accommodate him in their homes and sometimes they took hold o his she camel’s halter, but he said to one and all: "Let her go her way. She is guided by God." The Prophet’s she camel knelt by herself in front of Abu Ayyub’s house. Thus, the Prophet (Peace Be Upon Him) stayed with Abu Ayyub (Allah be pleased with him), who paid him the greatest respect and did all he could to entertain the honored guests.
The place where the Prophet’s (Peace Be Upon Him) she camel knelt by herself was then used for drying the dates and belonged to two orphan boys. The Prophet (Peace Be Upon Him) asked them to name the price of the yard. They answered, "Nay, but we shall make thee a gift of it, O Prophet of Allah!" The Prophet (Peace Be Upon Him), however, refused their offer, paid them its price and built a mosque over there which is known as "The Prophet’s Mosque". The Prophet (Peace Be Upon Him) himself carried the unburned bricks for construction of the building along with the other Muslims.