Marrakesh or Marrakech was founded in 1062 under the reign of the Almoravid king Yusuf ibn Tashfin. Quickly many mosques and madrassas were built and the city became a major center for traffic between the western Maghreb and sub-Saharan Africa.
Many palaces were built using Andalusian craftsmen from Córdoba and Seville, who brought the Umayyad style characterized by carved and lobed arched domes.
In 1122 the city was fortified by walls by the son of Youssef Ibn Tachfine Ali Ben Youssef.
In 1147 the Almoravid lost the city to the Almohad and almost all the monuments and palaces were destroyed by the Almohads as they considered the Almoravid to be heretics. In 1184 they built the impressive Koutoubia Mosque on the ruins of an Almoravid Palace.
In the sixteenth century, Marrakesh became the capital of the Saadian Empire and the city was embellished and restored during the reign of Ahmed Al-Mansur Ad Dhahbi (‘the golden’ in Arabic) who brought more than half a ton of gold from Timbuktu (Mali). This gold was partly used to build the sumptuous El Badi Palace.
After the end of the Saadi Dynasty in 1659, the Alaouite dynasty took control over Morocco and Meknes became the new capital of the Empire.