Middle Ages
The Muslim conquest of the Maghreb took place between 647 and 709, marking the Arab-Islamic expansion into North Africa, which was then divided between Byzantine-controlled coastal territories and independent Berber kingdoms and tribes in the interior. The conquest unfolded in three main phases and ultimately brought most of the region under Umayyad Caliphate control.
The first invasion (647–648), led by Abdallah ibn Saad under Caliph Uthman, targeted the Exarchate of Carthage. The Arabs defeated the Byzantine patrician Gregory at the Battle of Sufetula, weakening Byzantine authority in Ifriqiya. However, the campaign did not extend beyond raiding. After a period of civil war in the Muslim world, a second wave began around 665–689. Oqba ibn Nafi played a central role: in 670, he founded the city of Kairouan, which became a major Islamic base and cultural centre. He led ambitious campaigns deep into the interior, reportedly reaching the Atlantic coast, but faced strong resistance from Byzantine and Berber forces. A coalition led by the Berber leader Kusayla ambushed and killed Oqba at the Battle of Tahouda in 683. Kusayla temporarily captured Kairouan before being defeated.
The third and decisive phase (697–709) was led by Hassan ibn al-Nu'man and later Musa ibn Nusayr. Hassan recaptured and destroyed Carthage in 697 after fierce fighting against Byzantine reinforcements. A major Berber resistance then emerged under the legendary queen Kahina (Dihya), who initially defeated the Arabs in the Aurès Mountains. However, Hassan returned with fresh troops, defeated and killed Kahina around 697. Musa ibn Nusayr completed the conquest of the western Maghreb, subduing Berber tribes, capturing Tangier, and integrating many converted Berbers into the Muslim army. By 709, the entire Maghreb was under Umayyad control.
Following the Berber general Tariq ibn Ziyad's conquest of Visigothic Spain in 711, Islam had already spread throughout North Africa, and Berbers actively participated in raids into Europe, reaching as far as Lyon and Autun in France. However, Berber converts were still treated as second-class non-Arabs; the difficult conquest of the Maghreb prompted the Umayyads to impose heavy taxation and oppressive governance. Attracted by ideals of equality and religious purity, many Berbers supported Kharijite movements, triggering frequent revolts in Ifriqiya.
Following the Berber revolt numerous independent states emerged across the Maghreb. In 778, Abdel Rahman Ibn Rustam established a Kharijite emirate at Tahert in central Algeria known as the Rustamid imamate, marking the first independent Muslim state in the Maghrib. At its peak, the kingdom extended from Tlemcen to Tripoli. It prospered through trans-Saharan trade. The Rustamids faced constant threats from the Aghlabids, backed by the Abbasid Caliphate, in the east, and the Alid Idrisids in the west. Due to the strict religious nature of Ibadi society, the imams frequently dealt with internal rebellions, which weakened their authority unless the ruler was particularly charismatic. The dynasty was defeated by the Fatimids in 909, prompting the Ibadis to settle in the M'zab region.
The Fatimid da'wa entered the Maghreb through the skilled Ismaili Shia missionary Abu Abdullah al-San'ani (al-Shi'i), who arrived around 900 and settled among the Kabyle Kutama Berbers near Sétif. He gradually gained their support through preaching the coming of the Mahdi, organized them militarily, and succeeded in overthrowing the Aghlabid dynasty. In 909, he captured Kairouan and prepared the ground for the Fatimid state. He then liberated Ubayd Allah al-Mahdi from prison in Sijilmasa and handed him power. Al-Mahdi declared himself Caliph in 910, becoming the founder of the Fatimid Caliphate in Ifriqiya (Tunisia). The Fatimids imposed Ismaili Shia doctrine, faced strong opposition from the Sunni Maliki population, and dealt with several revolts, especially the major rebellion of Abu Yazid (the Man of the Donkey).
The Fatimids built a powerful army and navy and achieved military successes. They maintained control of Sicily, raided northern Italy (934–935 and 1004–1015), and developed a prosperous economy there, with many mosques, sugar cane, papyrus, and cotton production that rivalled Spain. In this way, the Fatimids established a powerful North African empire that would not be rivalled until the rise of the Almoravids and Almohads. Their greatest achievement was the successful shift of the caliphate's centre to Egypt; Under al-Mu'izz, the brilliant general Jawhar al-Siqilli conquered Egypt in 969, founded Cairo and al-Azhar University, and the Fatimids moved their capital to Egypt in 971.
After the Fatimids transferred their capital to Egypt in 971, they appointed Buluggin ibn Ziri, a Sanhaja Berber leader, as their governor over Ifriqiya and the central Maghreb. This marked the beginning of the Zirid Dynasty (362–543 AH / 973–1152 CE), which ruled from Achir then al-Mansuriyya near Kairouan. Buluggin founded the cities of Algiers, Médéa and Miliana, making central Algeria politically important. He then expanded his authority across Algeria and most of Morocco briefly, fighting Zenata tribes. Under al-Mu'izz ibn Badis, the Zirids cut ties with the Shia Fatimids in 1043, adopted Sunni Islam, and recognized the Abbasid Caliphate. In retaliation, the Fatimids sent the Arab tribes of Banū Hilāl and Banū Sulaym, whose invasion caused widespread destruction, especially in Kairouan. The Zirid state gradually weakened and fragmented.
A branch of the family, led by Hammad ibn Buluggin, broke away and established the Hammadid Dynasty (408–552 AH / 1018–1152 CE) in central Algeria. Their first capital was Qal'at Bani Hammad, later moving to Béjaïa (Bougie), which became a major prosperous city. The Hammadids developed a strong navy, promoted agriculture, industry, trade, and culture. Cities like Al-Qal’a' and Béjaïa flourished with scholars, poets, and architects. However, the dynasty suffered from internal divisions, revolts, attacks by the Almoravids, and Genoese raids on the coast. The Hammadids were finally defeated by Abd al-Mu'min, the founder of the Almohad Caliphate, in 1152, ending both Sanhaja dynasties in the region.
The Almoravids (Al-Murabitun), a puritanical religious-military movement of Sanhaja Berbers (mainly the Lamtuna tribe) from the Sahara in Mauritania, was founded in the mid-11th century by the Maliki scholar Abd Allah ibn Yasin. The movement emphasized strict adherence to Maliki Sunni Islam. Under leaders like Yusuf ibn Tashfin, they built a powerful empire, establishing Marrakesh as their capital in 1062. They conquered Sijilmasa, Fez, much of western and central Algeria (including Tlemcen, Oran, and Algiers in 1082), and defeated the Ghana Empire in the south. They also intervened in al-Andalus (Spain), defeating Christian forces and extending their rule there. The Almoravids strengthened Maliki Islam and brought Andalusian cultural influence to the Maghreb, but their rigid legalism later contributed to their downfall. They were overthrown by the Almohads, who captured Marrakesh in 1147.
The Almoravids' successors were the Almohads (Al-Muwahhidun), meaning "Unitarians"; a reformist movement founded by Muhammad ibn Tumart, a Masmuda Berber who proclaimed himself the Mahdi. They emphasized the absolute unity of God (Tawhid) and opposed what they viewed as Almoravid religious errors. Abd al-Mu'min became the first Almohad Caliph and completed the conquest of the Maghreb by 1147, unifying the region for the first time. In Algeria, they ended the Hammadid dynasty by capturing Béjaïa, Algiers, and Qal'at Bani Hammad. The empire reached its peak under Abu Yaqub Yusuf and Yaqub al-Mansur, who patronized philosophy (including Ibn Rushd/Averroes and Ibn Tufayl), arts, and architecture, while maintaining control in al-Andalus. However, major defeats against Christian forces, especially at Las Navas de Tolosa in 1212, and internal divisions led to the empire's collapse. By the mid-13th century, the Almohad state fragmented, giving rise to the Hafsids in Ifriqiya, the Zayyanids in Tlemcen, and the Marinids in Fez.
Following the collapse of the Almohad Empire, Yaghmurasen ibn Zayyan founded a Zanata Berber dynasty known as the Zayyanid or Abd al-Wadid dynasty, which ruled the central Maghrib from 1236 to 1550. The dynasty produced 27 rulers and made Tlemcen its capital. The Zayyanids generally used the title of emir, though some adopted shaykh or khalifa. Their administration included qadis and wazirs. Thanks to its strategic location on the trans-Saharan trade routes, Tlemcen flourished as a major political, economic, and cultural centre, famous for trade in leather goods, precious metals, and slaves. Zayyanid rulers actively supported learning by constructing mosques and madrasas, turning their capital into an important theological and intellectual hub. Their history is relatively well documented, particularly through the works of the famous historian Ibn Khaldun.
Geopolitically, the kingdom was constantly threatened by its powerful neighbours — the Marinids of Morocco to the west and the Hafsids of Ifriqiya to the east — while also facing internal family intrigues and hostility from rival Zanata tribes. Several rulers stood out in the 14th century, notably Abu Hammu I (1308–1318), who restored Tlemcen and expanded influence eastward; Abu Tashfin I (1318–1337), a patron of education and literature who died defending the city against the Marinids; Abu Hammu II (1359–1389), known for his resilience in recovering Tlemcen multiple times; and his son Abu Tashfin II, who conspired against him, making Tlemcen a Marinid vassal. Over time, the dynasty weakened due to endless external conflicts and internal betrayals, with the last Zayyanid rulers becoming Spanish then Ottoman vassals.