Under Muhammad and the Rashidun (622–660 CE) inscribed in the mosque which says "A prayer in this mosque of mine is better than a thousand prayers anywhere else, except for
Al-Masjid al-Haram." The mosque was built by Muhammad in 622
CE after his arrival in Medina. Riding a camel called Qaswa, he arrived at the place where this mosque was built, which was being used as a burial ground. Refusing to accept the land as a gift from the two orphans, Sahl and Suhayl, who owned the land, he bought the land which was paid for by Abu Ayyub
al-Ansari, and it took seven months to complete the construction of the mosque. It measured . The roof which was supported by palm trunks was made of beaten clay and palm leaves. It was at a height of . The three doors of the mosque were the
Bāb ar-Raḥmah (, "Gate of the Mercy") to the south,
Bāb Jibrīl (, "Gate of
Gabriel") to the west, and
Bāb an-Nisāʾ (, "Gate of the Women") to the east. At this time point in the history of the mosque, the wall of the
qibla was facing north to
Jerusalem, and the
Suffah was along the northern wall. In the year 7 AH, after the
Battle of Khaybar, the mosque was expanded to on each side, and three rows of columns were built beside the west wall, which became the place of praying. The mosque remained unaltered during the reign of Abu Bakr. Umar demolished all the houses around the mosque, except those of
Muhammad's wives, to expand it. The new mosque's dimensions became . Sun-dried mud bricks were used to construct the walls of the enclosure. Besides strewing pebbles on the floor, the roof's height was increased to . Umar constructed three more gates for entrance. He also added
Al-Buṭayḥah () for people to recite poetry. The third Rashidun caliph
Uthman demolished the mosque in 649. Ten months were spent in building the new rectangular shaped mosque whose face was turned towards the
Kaaba in Mecca. The new mosque measured . The number of gates as well as their names remained the same. The enclosure was made of stones laid in mortar. The palm trunk columns were replaced by stone columns which were joined by iron clamps.
Teakwood was used in reconstructing the ceiling filza.
Umayyad era In 706 or 707, the
Umayyad caliph
al-Walid I () instructed his governor of Medina, the future caliph
Umar ibn Abd al-Aziz, to significantly enlarge the mosque. According to the architectural historian Robert Hillenbrand, the building of a large scale mosque in Medina, the original center of the caliphate, was an "acknowledgement" by al-Walid of "his own roots and those of Islam itself" and possibly an attempt to appease Medinan resentment at the loss of the city's political importance to
Syria under the Umayyads. It took three years for the work to be completed. Raw materials were procured from the
Byzantine Empire. Al-Walid lavished large sums for the mosque's reconstruction and supplied mosaics and Greek and
Coptic craftsmen. The area of the mosque was increased from the area of Uthman's time, to . For the first time,
porticoes were built in the mosque connecting the northern part of the structure to the sanctuary. The reconstruction preserved the location of the
qibla wall (in the direction of prayer), but Umar ordered the addition of a curved niche to it and this became the first concave
mihrab in
Islamic architecture. The renovated mosque was richly decorated with marble paneling and mosaics covering its walls. Later written accounts, such as that of
Ibn Jubayr (1184), described the mosaics as containing inscriptions and depicting landscapes with trees, suggesting that they resembled the style of contemporary Umayyad mosaics in the
Dome of the Rock in Jerusalem and the
Great Mosque of Damascus. The mosque's redevelopment entailed the demolition of the living quarters of
Muhammad's wives and the expansion of the structure to incorporate the graves of Muhammad, Abu Bakr and Umar. The vocal opposition to the demolition of Muhammad's home from local religious circles was dismissed by al-Walid. A wall was built to segregate the mosque and the houses of the wives of Muhammad. The mosque was reconstructed in a trapezoid shape with the length of the longer side being . According to the 10th-century writer
Ibn Rusta,
minarets were also built for the first time during al-Walid's expansion as four towers were added to the mosque's corners. They may be the first minarets in Islamic architecture, though it is not clear exactly what purpose these towers served in this early period. At the time of Ibn Rusta's writing, only one of the original four towers remained standing. The southwest minaret was demolished in 716 on the orders of
Sulayman ibn Abd al-Malik.
Abbasid era The
Abbasid caliph
al-Mahdi () extended the mosque to the north by . His name was also inscribed on the walls of the mosque. He also planned to remove six steps to the
minbar, but abandoned this idea, fearing damage to the wooden platforms on which they were built. The project required the demolition of the two northern minarets of al-Walid's time but they were replaced by two new towers at the northern corners of the new expansion. According to an inscription of
Ibn Qutaybah, the caliph
al-Ma'mun () did "unspecified work" on the mosque.
Al-Mutawakkil () lined the enclosure of Muhammad's tomb with marble.
Mamluk era , which was given its signature color in 1837 In 1269, the
Mamluk sultan
Baybars sent dozens of artisans led by the eunuch Emir Jamal al-Din Muhsin al-Salihi to rebuild the sanctuary, including enclosures around the tombs of Muhammad and of Fatima. in 1279 sultan
Qalawun added a wooden dome over the tomb of the prophet, and rebuilt the south-western minaret (Bab Al-Salam minaret), which still retains its lower structure but with the upper section being built during the Ottoman era. In 1474 the Mamluk sultan
Qaitbay ordered major renovation to be conducted on the mosque's roofs, columns, walls and minarets, the work also included the building of a stone dome over the prophet's tomb in 1476. and in 1483-1484 he reconstructed the Nabawi mihrab, Uthmani Mirhab and the Tahajjud Mihrab, and also rebuilt the south-eastern minaret (main minaret) next to the green dome and a western minaret، the latter was demolished during the Saudi expansions. except for the dome over Muhammad's tomb. As per the
sahih hadiths, they considered the veneration of tombs and places, which were thought to possess supernatural powers, as an offence against
tawhid, and an act of
shirk. Muhammad's tomb was stripped of its gold and jewel ornaments, but the dome was preserved either because of an unsuccessful attempt to demolish its complex and hardened structure, or because some time ago,
Muhammad ibn Abd al-Wahhab, founder of the Wahhabi movement, wrote that he did not wish to see the dome destroyed. After the foundation of the Kingdom of
Saudi Arabia in 1932, the mosque underwent several major modifications. In 1951,
King Abdulaziz (1932–1953) ordered demolitions around the mosque to make way for new wings to the east and west of the prayer hall, which consisted of concrete columns with pointed arches. Older columns were reinforced with concrete and braced with copper rings at the top. The
Suleymaniyya and
Mecidiyye minarets were replaced with two minarets in
Mamluk revival style. Two additional minarets were erected to the northeast and northwest of the mosque. A library was built along the western wall to house historic Qurans and other religious texts. In 1974,
King Faisal added to the mosque. The area of the mosque was also expanded during the reign of
King Fahd in 1985.
Bulldozers were used to demolish buildings around the mosque. In 1992, when it was completed, the mosque took over of space. Escalators and 27 courtyards were among the additions to the mosque. A$6 billion project to increase the area of the mosque was announced in September 2012. After completion, the mosque should accommodate between 1.6 million to 2 million worshippers. == Architecture ==