During the 1100s AD, while the Ayyubids were taking over Egypt, the Almohad dynasty managed to conquer and rule the rest of North Africa (modern Libya, Tunisia, Algeria and Morocco) and Iberia (modern Spain and Portugal). When they conquered Cordoba in 1148, the Almohads threw all the Jews out of town, among them the young Maimonides.
The Alcazar in Seville
The Almohads soon moved their capital city from Africa to Seville in Spain. They built a great mosque in Seville (only the minaret is still there), and a palace (part of that is still there, in the Alcazar). The Almohads were religious reformers, who tried to purify Islam and get people to think of Allah as a spirit, and not think of him as too much like a man.
Under the Almohads, there were many schools and universities in North Africa and Spain. In the late 1100s, the European traveller Fibonacci of Pisa learned about Arabic numerals at a school in Algiers under Almohad rule.
But the Almohads could not hold their empire together for very long. Soon after 1200 AD, rebellions and fights destroyed the Almohad empire.
The Christian kingdoms of Northern Spain – Castile, Aragon, and Portugal – took advantage of the Almohad weakness to conquer southern Spain. First they won a big battle and took Toledo in 1212; then they took Cordoba in 1236, Valencia in 1238, and Seville in 1248. By 1250 the only important Spanish city still under Islamic control was Granada. The people of Granada soon threw out the Almohads and replaced them with the Nasrids.
Meanwhile in North Africa, the Almohad empire had split into three new kingdoms. The Hafsids ruled the east (modern Libya and Tunisia). The ‘Abd al-Wadids ruled the middle (modern Algeria). And the Marinids ruled the west (modern Morocco).