The Almoravids emerged in the eleventh century as a religious and political movement among the Sanhaja, Berber (Amazigh) peoples of the western Sahara. They founded Marrakesh around 1062–1070 and united much of the Maghreb. Their southern expansion was connected with control of Saharan trade routes, although their supposed conquest of the Ghana Empire remains disputed. In 1086, responding to an appeal from Muslim rulers in Iberia, they defeated Alfonso VI at Sagrajas and gradually annexed many of the small kingdoms of al-Andalus.
A dynasty committed originally to austere religious life found itself ruling wealthy cities with centuries of cultural tradition. Taxation, military expenditure and political tensions generated discontent. In the early twelfth century Ibn Tumart preached a return to a rigorous belief in the unity of God. His followers, the Almohads, captured Marrakesh in 1147 and extended their rule across Iberia and North Africa. Architecture, philosophy and medicine flourished, despite occasional religious persecution. The philosopher Averroes, who fell from favour in 1195, illustrates these tensions.
Koutoubia Mosque
The Almohad defeat at Las Navas de Tolosa in 1212 accelerated the collapse of their power in Iberia. The last Muslim kingdom on the peninsula, Nasrid Granada, survived until 1492 through a combination of trade, diplomacy and tribute payments. Its art, exemplified by the Alhambra, bears witness to a remarkably creative society.
Ait-Ben-Haddou, between the Sahara and Marrakesh
In the Maghreb, the Marinids captured Marrakesh in 1269. Cities and religious schools flourished under their rule, particularly in Fez. The Portuguese seized Ceuta in 1415, but not Morocco as a whole. Repeated changes of dynasty did not sever the connections between the two shores of the western Mediterranean.