Madrid was founded in the mid-9th century (between 853 and 865) by Muhammad I, Emir of Cordoba, as a military settlement, and it remained under Muslim rule until it was conquered by King Alfonso VI of Castile in 1085. From those centuries, we can still find remains of the original walls, in addition to some remains scattered around the vicinity of the Almudena Cathedral and Plaza de Oriente.
In 1976, 18 Muslim countries with diplomatic representation in Spain signed an agreement to build a mosque in Madrid. However, the project was delayed for 11 years, until King Fahd of Saudi Arabia provided the necessary funding to complete construction. Finally, in 1992, the Saudi monarch and Juan Carlos I inaugurated the mosque. Over its six floors, in addition to the mosque, we can find a school, a library, a museum, two exhibition halls, a gym and a restaurant.