The Prophet (S.A.W) entered the city on Friday. The entire city had come out to receive the Prophet (S.A.W) of Islam. They were waiting to welcome him. It was an occasion of festivities and celebrations, and with his arrival history of Islam began with the establishment of the rule of justice and equality through Quran. Islam replaced superstitions, opinions, ignorance, tyrannies and oppressions to faith, learning, brotherhood and equality. From that day Yasrib became Madinatul Nabi (the city of the Prophet (S.A.W)). And is known as Madina even today.
As every tribe wanted to be the host of the Prophet (S.A.W) and the Prophet (S.A.W) did not wish to displease anyone he declared that he will be the guest of the house where his camel will take him. The camel took him to the house of Abu Ayub Ansari and stopped. Abu Ayub Ansari belonged to the clan of Bani Najjar to which Abdul Mutallibs (Prophet (S.A.W)s grandfather) mother Salma belonged. Therefore the relationship between the Prophet (S.A.W) and the people of Yasrib specially the tribe of Bani Najjar was not new. The Prophet (S.A.W)s great grand father Hashim married Salma a widow of Bani Najjar tribe at Nabt a place on the way to Yasrib. After a few days stay with her, Hashim went away to Syria where he fell sick and died. [Tabaqat, Vol. VI, page 46] Salma who was pregnant gave birth to Abdul Mutallib but the Hashmis who all lived in Mecca did not know about it nor of Hashmis marriage with Salma. It was only when Saabit Ibne Manzar Ibne Kharam (father of poet Hassan Bin Saabit] came to Mecca for pilgrimage that he met Mutallib and informed him about the marriage and the child. Mutallib immediately went to Yasrib and persuaded Salma and her tribesmen to give him his late brothers child, who was now grown-up and a true picture of his late father. It was a great shock for Salma to part with her only child but Mutallib prevailed upon her and the people of Bani Najjar too persuaded her to give the child to Mutallib as the child rightfully belonged to his family. They not only allowed Mutallib to take the child with him as a goodwill gesture but the entire tribe accompanied him to Mecca and stayed as a guest of Mutallib. Perhaps it was this gratitude of the Prophet (S.A.W) that he chose to stay with Abu Ayub Ansari a member of the tribe of Bani Najjar [Tabaqat Ibne Saad].
The first problem of the Prophet (S.A.W) in Madina was the rehabilitation of the immigrants of Mecca many of whom were very poor and without any shelter food or relatives. But the generous people of Madina solved this problem by offering their belongings to the immigrants to be equally shared by them. The Prophet (S.A.W) further created brotherhood between the Muslims of Mecca and Madina by offering ones hand into the hand of another, considering the nature, qualification and status of each of them. No class or tribal distinctions were considered. For instance Abu Bakr was made the brother Umar Bin Khattab. Though both belonged to two different tribes of Mecca, and the tribe of Abu Bakr was not considered as respectable as that of Umar Bin Khattab. Talha was given the hand of Zubair, and Usman Bin Affan made the brother of his own brother in law Abdur Rehman Bin Aof. The Prophet (S.A.W) gave his own uncles hand in the hand of Zaid Bin Harsa and for his ownself chose Ali (A.S.) Ibne Abi Talib his cousin to be his brother and declared, "Ali is my brother in this world and the next too."
He inculcated the fundamental principles of Islam that brotherhood depended not on blood but only on faith. The right of family inheritance within Islam were expressly valid and sacred. These mandates resulted a considerable expansion of the Muslim community.
After establishing the base of his Islamic society the first act of the Prophet (S.A.W) was to buy a piece of land from Suhail and Sahl the two brothers to build a mosque which is known as Masjid-e-Nabavi (Prophet (S.A.W)s Mosque) with the help of the Muslims of Mecca and Madina. He himself worked as a labourer and while working he recited, "Only everlasting life has a value. May Allah have mercy on the immigrants and my companions." The mosque measured 4200 cubits and had no roof. The walls were built of mud. The roof was built from the branches of date leaves. Ammar-e-Yasir a companion of the Prophet (S.A.W) could not see the Prophet (S.A.W) himself working as a labourer and worked the Prophet (S.A.W)s share of labour also. Ali (A.S.) took the job of bringing mud and stone and as he carried the weight he recited : "Whosoever builds a mosque, and works there sitting or standing, Puts up with the pain of labour, while others shrink work, For fear of dust and pain, both of these verily, Cannot equal each other."
The area of the mosque was further extended by 2475 meters by the Prophet (S.A.W) after the victory of Khaiber in the year 7 A.H. In the main mosque, he built many pillars and each pillar was given a name where specific work was carried out. For instance the column of Haris (guard) was a place where the Prophet (S.A.W) met those people with whom he was not familiar, and Ali (A.S.) always stood near him as a body guard. There was another column by the name "the column of Mohajareen (Immigrants)." This column was between the pulpit and the Prophet (S.A.W)s house which was attached to the house. This was the place where the immigrants generally assembled.
After the death of the Prophet (S.A.W) this mosque was built several times and its area enlarged. Umar Ibnul Khattab was the first person after the death of the Prophet (S.A.W) who thought of rebuilding it during his regime. He tried to acquire the house of the Prophet (S.A.W)s uncle Abbas for extending the area of the mosque but Abbas refused to donate or sell the house to Umar. The matter was then referred to one Obay Ibne Kaab for arbitration. After hearing the case of Abbas, Obay Bin Kaab narrated the incident of the construction of Palestine where the owners of one piece of land similarly refused to sell it to David who wanted to construct Palestine at the behest of God. When David attempted to acquire it by force, God reprimanded David and did not permit him to construct Palestine. God then ordered Solomon to build Palestine, which he did. Umar not satisfied with the award of Obay Bin Kaab referred the matter to Abu Zar-e-Ghaffari and other companions of the Prophet (S.A.W) but they too endorsed the verdict of Ibn Kaab and confirmed the tradition narrated by him. This silenced Umar and he dropped the idea of acquiring it. Abbas then himself donated his house for the expansion of the mosque [Tabaqat-e-Ibne Saad]. Similarly during the year 26 A.H. Usman expanded the boundaries of the mosque still further by purchasing the neighboring houses. When some owners resisted Usman forcefully demolished their houses and deposited the price of those houses in the government treasury. When they protested over his action, Usman put all of them in jail. [Tabari Vol 5 page 47; Kaamil Vol 3, page 36].
In the year 1277 A.H. the area was once again expanded to 10300 meters. The construction on this red stone mosque with its beautiful calligraphy took thirteen years to complete. Another repair took place in 1375 A.H. preserving the old building and constructing another magnificent building of 6029 meters with 706 columns and two places for the Moazzin who recites Azaan). The total area of the new mosque is today 16327 square meters (and is expanding even more).
After the completion of the mosque the Prophet (S.A.W) and his immigrants and friends started constructing their own houses around the mosque. Each one having an extra door which opened in the Mosque. The whole project of building the houses took seven months to complete. After which the Prophet (S.A.W) and Ali (A.S.) shifted to their new house.
After six moths of stay at Madina the Prophet (S.A.W) received an invitation from Umme Basher and Bani Saleem tribe to visit their village which was to the north west of Madina. The Prophet (S.A.W) led the noon prayer facing Jerusalem. It was here that the Prophet (S.A.W) received the revelation from God ordering him to change the direction of prayers from Jerusalem to Kaaba in Mecca. From then on Kaaba became the permanent Qibla (direction) for the ritual prayers of all the Muslims of the world. And from that day this mosque is known as Masjid-e-Qiblatain.