# History of early Islamic Tunisia

Part of a series on the :
History of Tunisia :
PrehistoricPrehistory :
Ancient Carthage12th C.–146 BC 1st Roman (Province)146 BC–435 Vandal435–534 2nd Roman (Byzantine) / Byzantine North Africa534–698 Prefecture534–590 Exarchate590–698 :
Early Islamic Umayyad698–750 Abbasid750–800 Aghlabid800–909 Fatimid909–973 :
Medieval Zirid973–1148 Norman1148–1160 Almohad1160–1229 Hafsid1229–1574 :
Early modern Ottoman 1574–1705 Husainid 1705–1881 :
Modern French rule 1881–1956 Kingdom of Tunisia 1956–1957 Bourguiba rule 1957–1987 Ben Ali coup 1987 Ben Ali rule 1987–2011 Tunisian revolution 2010–2011 Political crisis 2013–2014 COVID-19 pandemic 2020 Saied self-coup 2021 :
Africa portal • History portal :
vte :
The History of early Islamic Tunisia opens with the arrival of the Arabs who brought their language and the religion of Islam, and its calendar. The Arab conquest followed strategy designed by the Umayyad Caliphate regarding its long-term conflict with the Byzantine Empire. The native Berbers eventually converted to Islam. They might have seen some similarities between themselves and the Arabs, in similar cognate culture, such as familiarity with a pastoral way of life. The first local Islamic ruling house, the Aghlabids, consisted primarily of rule by leading members of this Arab tribe. Fundamental elements of Islamic civilization were established. Although accepting Islam, many Berbers nonetheless resisted rule by the Arabs, establishing the Rustamid kingdom following the Kharijite revolt. Next in Ifriqiya (Tunisia) arose the Shia Fatimids, inspired by a few immigrants from the east yet consisting for the most part of Ifriqiya Berbers. The Fatimids later expanded their rule east, through conquest by Berber armies of Egypt, and established their caliphate there which came to include Syria and the Hejaz.

## Umayyad Caliphate in Ifriqiya

After the initial period of the four rightly-guided caliphs (632-661) following the death of Muhammad (570-632), the ruling family of the Umayyads took firm control of the new Muslim state. The Umayyad Caliphate (661-750) ruled from the city of Damascus; their first Caliph Mu'awiya (602-680, r.661-680) directed Muslim forces in their on-going military contest with the Byzantine Empire. Decades earlier the Byzantine provinces of Syria and Egypt had fallen to Islamic arms. Under Mu'awiya the Umayyad Caliphate could see how the foreign lands west of Egypt figured in the "geo-political" and military strategy of this struggle. Hence there began the decades-long undertaking resulting in the Umayyad conquest of North Africa.

### Islamic conquest

In 670 an Arab Muslim army under Uqba ibn Nafi, who had commanded an earlier incursion in 666, entered the region of Ifriqiya (a newly coined Arabic word for the prior Roman Province of Africa). Marching overland the Arabs by-passed the fortified Byzantine positions along the Mediterranean coast. In the more arid south of Ifriqiya, the city of Kairouan (military outpost in Persian) was established as their base, and the building of its famous Mosque was begun. Then, from 675 to 682, Dinar ibn Abu al-Muhadjir took over direction of the Muslim invasion. Armed Berber forces constituted the main resistance to the Arabs. Apparently these Berbers were primarily composed of sedentary Christians from the Awreba tribe and perhaps also the Sanhadja confederation; they were led by Kusaila. In the late 670s, the Arab armies defeated these Berbers forces and made Kusaila their prisoner.
In 682, Uqba ibn Nafi resumed command. He defeated another alliance of Berber forces near Tahirt (Algeria), then proceeded westward in a long series of military triumphs, eventually reaching the Atlantic coast, where he is said to have lamented that before him lay no more lands to conquer for Islam. Episodes from Uqba's campaigns became legend throughout the Maghrib. Yet Kusaila, the Berber leader held prisoner, escaped. Later Kusaila organized and led a fresh Berber uprising, which interrupted the conquest and claimed the life of the famous Arab leader, Uqba. Kusaila then formed an enlarged Berber kingdom. Yet Zuhair b. Qais, the deputy of the fallen leader Uqba ibn Nafi, enlisted Zanata Berber tribes from Cyrenaica to fight for the cause of Islam, and in 686 managed to overrun, defeat, and terminate the kingdom newly formed by Kusaila.
Under the Caliph 'Abd al-Malik (685-705), ruling from Damascus, the Umayyad conquest of North Africa was to advance close to completion. In Egypt a new army of forty thousand was assembled, to be commanded by Hassan ibn al-Nu'man (known to Arabs as "the honest old man"). Meanwhile, the weakened Byzantines managed to reinforce somewhat their positions. The Arab Muslim army crossed the Cyrene and Tripoli without opposition, then quickly attacked and captured Carthage.
The Berbers, however, continued to offer stiff resistance, then being led by a woman of the Jarawa tribe, whom the Muslims called "the prophetess" [al-Kahina in Arabic]; her actual name was approximately Damiya. On the river Nini, an alliance of Berbers under the Kahina Damiya sharply defeated the Muslim armies under al-Nu'man, who escaped then eastward, returning to Cyrenaica. Thereupon, the Byzantines took advantage of the Berber victory by reoccupying Carthage. Unlike the Berber Kusaila ten years earlier, Damiya did not establish a larger state, evidently being content to rule merely her own Jawara tribe. Some commentators speculate that, to the Kahina Damiya, the invading Arabs appeared primarily interested in booty, because she then commenced to sack and pillage the region, apparently to make it unattractive to raiders looking for the spoils of war; of course, it also made her own forces hotly unpopular to local inhabitants. Yet she did not attack the Muslim base at Kairouan. From Egypt in 698 the Caliph 'Abdul-Malik sent reinforcements to al-Nu'man, who then reentered Ifriqiya. Although she told her two sons to go over to the Arabs, she herself continued resistance and again gave battle. The fortunes of war deserted her, and al-Nu'man emerged victorious. It is said that at Bir al-Kahina [well of the prophetess] in the Auras mountains, Damiya was slain.
In 705 Hassan b. al-Nu'man stormed Carthage, overcame and sacked it, leaving it destroyed. A similar fate befell the proximous city of Utica. At Tunis, a small town dating back to the Punic era, and situated near the ruins of Carthage, al-Numan founded a naval base. Muslim ships fitted for war began to assert dominance over the adjacent Mediterranean coast; hence the Byzantines then made their final withdrawal from North Africa. The Arabs called the region al-Maghrib: the "sunset land" or "the west". Then al-Nu'man was replaced as Muslim military leader by Musa ibn Nusair, who substantially completed the conquest of al-Maghrib. Ibn Nusair took the city of Tangier on the Atlantic coast, and appointed as its governor the Berber leader Tariq Abu Zara. Tariq would lead the Muslim conquest of Hispania, begun in 711.

### Berber role

The Berbers, also known as the Amazigh, "converted en masse as tribes and assimilated juridically to the Arabs", writes Prof. Hodgson; he then comments that the Berbers were to play a role in the west parallel to that played by the Arabs elsewhere in Islam. For centuries the Berbers had lived as semi-pastoralists in or near arid lands at the fringe of civilization, sustaining their isolated identity somewhat like the Arabs. "The Maghrib, islanded between Mediterranean and Sahara, was to the Berbers what Arabia... was to the Arabs." Hodgson explains: although the Berbers enjoyed more rainfall than the Arabs, their higher mountains made their settlements likewise difficult to access; and though the imperial Roman cities were more proximous, those cities never incorporated the countryside with a network of market towns, but instead remained aloof from the indigenous rural Berbers.
A counter argument would be that the Berbers at first merely participated in the martial success of the Arab Muslims; the better historical choice for the Berbers would be more uniquely ethnic and thus more authentic, i.e., to articulate their own inner character and fate, and follow that. Prof. Abdallah Laroui, however, interprets the North African panorama as indicating that the Berbers did in fact carve out for themselves an independent role. "From the first century B.C. to the eighth century A.D. the will of the Berbers to be themselves is revealed by the continuity of their efforts to reconstitute their kingdoms of the Carthaginian period, and in this sense the movement was crowned with success." Here Laroui apparently favorably compares the ancient Berber King Masinissa and his regime, e.g., to the Rustamid kingdom, and later to the medieval Islamic Almoravids and Almohads, and to the Zirid and the Hafsid dynasties, all Berber creations. By choosing to ally not with nearby Europe, familiar in memory by the Roman past, but rather with the newcomers from distant Arabia, the Berbers knowingly decided their future and historical path. "Their hearts opened to the call of Islam because in it they saw a means of national liberation and territorial independence."
Environmental and geographic parallels between Berber and Arab are notable, as Hodgson discusses above. In addition, the languages spoken by the Semitic Arabs and by the Berbers are both included as members in the same world language family, the Afro-Asiatic, although Berber and Semitic form two different branches. Perhaps this linguistic kinship shares a further resonance, e.g., in mythic explanations, popular symbols, and religious preference, in some vital fundamentals of psychology, and in the media of culture and the context of tradition.
Evidently, long before and after the Islamic conquest, there was some popular sense of a strong and long-standing cultural connection between the Berbers and the Semites of the Levant, naturally with regard to Carthage, and in addition with regard to links yet more ancient and genetic. These claims of a remote ancestral relationship perhaps facilitated the Berber demand for equal footing with the Arab invaders within the religion of Islam following the conquest. Later in the medieval Maghrib, elaborate but fictitious genealogies would be created on the assumed foundation of an ancient Yemeni origin of the Berber people. Those fake Yemeni origins and genealogies of the Berbers were mocked by Ibn Hazm (994-1064) and discounted by Ibn Khaldun (1332–1406).
From Cyrenaica to al-Andalus, the superficially 'Arabized' Berbers continuously remained in communication with each other throughout the following centuries, sharing a common cultural identity. As a group their distinguishing features are not difficult to discern within Islam; e.g., while the ulama in the rest of Islam adopted for the most part either the Hanafi or the Shafi'i school of law, some Berbers in the west chose the Maliki madhhab, developing it in the course of time after their own fashion. Other Berbers chose the revolutionary Kharijite sect of Islam and used it to end Umayyad Arab rule in the Berber world. In the process of the Berbers becoming Muslim, the Arab colonists and migrants who settled among also in turn underwent a form of "Berberization".
Also inducing the Berbers to convert was the early lack of rigor in religious obligations, as well as the prospect of inclusion as warriors in the armies of conquest, with a corresponding share in booty and tribute. A few years later, in 711, the Berber Tariq ibn Ziyad would lead the Muslim invasion of the Visigothic Kingdom in Hispania. Additionally, many of the Arabs who came to settle in al-Maghrib were religious and political dissidents, often Kharijites who opposed the Umayyad rulers in Damascus and embraced egalitarian doctrines, both popular positions among the Berbers of North Africa who disliked Arab displays of superiority.
To locate its history of religion context, the Arab conquest and the Islamic conversion of the Berbers followed a centuries-long period of religious conflict and polarization of society in the old Roman Empire's Africa Province. Here, the Donatist schism within Christianity proved instrumental; it caused divisions in society, often between the rural Berbers, who were prominent in schismatic dissent, and the more urban orthodoxy of the Roman church. Too, the successor to the Romans, the Vandal Kingdom (439-534) also religiously polarized the Christian society by their attempt to force on others their own Arian form of Christianity. Alternatively, or concurrently, the Berbers were initially attracted to the Arabs because of their "proclivity for the desert and the steppes".
After the conquest and following the popular conversion, Ifriqiya constituted a proximous and natural focus for an Arab-Berber Islamic regime in North Africa, a center for culture and society. Ifriqiya was then the region with the most developed urban, commercial, and agricultural infrastructure, essential for such a comprehensive project as Islam developed.

## Aghlabid emirate under Abbasids
### Establishment

During the years immediately preceding the fall of the Umayyad Caliphate of Damascus (661-750), revolts arose among the Kharijite Berbers in Morocco which eventually disrupted the stability of the entire Maghrib (739-772). The Kharijites failed to establish strong lasting institutions, yet the small Rustamid kingdom persisted (which controlled southern Ifriqiyah); also the impact of the Berber Kharijite revolt changed the political landscape. Direct rule from the East by the Caliphs over Ifriqiya became untenable, even following the rapid establishment of the new Abbasid Caliphate of Baghdad in 750. Also, after several generations a local Arab-speaking aristocracy emerged in Ifriqiya, which became resentful of the distant caliphate's interference in local matters.
The Arab Muhallabids (771-793) negotiated with the 'Abbasids a wide discretion in the exercise of their governorship of Ifriqiya. One such governor was al-Aghlab ibn Salim (r. 765-767), a forefather of the Aghlabids. Decades later Muhallabid rule came undone. A minor rebellion in Tunis took a more ominous turn when it spread to Kairouan. The Caliph's governor was unable to restore order.
Ibrahim ibn al-Aghlab, a provincial leader (son of al-Aghlab ibn Salim), led a disciplined army; he did manage to reestablish stability in 797. Later he proposed to the 'Abbasid caliph Harun al-Rashid, that he be granted Ifriqiya (as the Arabs called the former Province of Africa) as a hereditary fief, with the title of amir; the caliph acquiesced in 800. Thereafter, although the 'Abbasids caliphs received an annual tribute and their suzerainty was referenced in the khubta at Friday prayers, their control was largely symbolic, e.g., in 864 the Caliph al-Mu'tasim "required" that a new wing be added to the Zaituna Mosque near Tunis.

### Political culture

Ibrahim ibn al-Aghlab (r.800-812) and his descendants, known as the Aghlabids (800-909), ruled in Ifriqiya from 800 to 909. The Aghlabids were predominantly of an Arab tribe the Bani Tamim. At that time there were perhaps 100,000 Arabs living in Ifriqiya, but of course the Berbers constituted the great majority. The Aghlabid military forces were drawn from: (a) immigrant Arab warriors (both those recently sent against the Berber Kharajite revolts, and those descendants of earlier Arab invasions), (b) Islamized and bilingual natives (Afariq), the Roman Africans, most of whom were Berbers, and (c) black slave soldiers from the south. The black soldiery formed the ruler's last resort.
At origin, Aghlabid rule was based on their opportune use of assertion and negotiation supplemented by effective military force, in order to control the populace and secure civil order, following a period of instability. In theory, the Aghlabids governed on behalf of the 'Abbasid Caliphate in Bagdad, whose prestige the Aghlabids held, enhanced their authority among the locals of Ifriqiya. Yet the Aghlabid regime failed to become popular. Despite the political peace and stability they initiated, followed by economic expansion and prosperity, including admired public construction projects, and despite a blossoming culture, political dissent was rife, and not confined to Berbers. Many in the Arabic-speaking elite developed an increasingly contrary attitude toward the Aghlabids, for several reasons.
First, in the army the Arab officer class became dissatisfied with the legitimacy of the regime, or used this as a pretext for disloyal ambition. This general attitude of insubordination meant that the internal quarreling within the military from time to time spilled over into public and violent struggles. Their latent hostility also surfaced when army factions began making extortionist demands directly on the population. A dangerous revolt from within the Arab army (the jund) broke out near Tunis and lasted from 824 until 826. The Aghlabids retreated to the south pre-Sahara, and were saved only by enlisting the aid of Berbers of the Kharajite Jarid. Later another revolt of 893 (said to be provoked by the cruelty of Ibrahim II Ibn Ahmad (r. 875-902), the ninth Aghlabid amir), was put down by the black soldiery.
Second, the Muslim ulema (clerics) looked with reproach on the ruling Aghlabids. Surface aggravation in religious circles arose from the un-Islamic lifestyle of the rulers. Disregarding the strong religious sentiments held by many in the emerging Muslim community, the Aghlabids often led lives of pleasure at variance to Islamic law, e.g., publicly drinking wine. In the context of the bitter charges against the Aghlabids for lax Islamic practice, which came from their rivals the Rustamid kingdom (predominantly Berber, see below), their well-known failings acquired importance. Another issue was that Aghlabid taxation policies were not sanctioned by the prevailing Maliki school of law. Opponents further criticized their contemptuous treatment of mawali Berbers who had embraced Islam, but were treated as infidels. The Islamic doctrine of equality regardless of race, i.e., as between Arab and Berber, became a cornerstone of the orthodox Sunni movement in the Maghrib, as it was developed in Kairouan by the Maliki school of law. These various Islamic principles formed the core of the prevalent hostility of Ifriqiya toward any rule by the Caliph from the East. They also helped to fuel anti-Aghlabid sentiment.
As recompense, the Aghlabid rulers saw that mosques were constructed or augmented, e.g., at Tunis: the Al-Zaytuna Mosque (Mosque of the Olive) (later home to its famous university, Ez-Zitouna); at Kairouan: Ibn Kayrun Mosque (or Mosque of the Three Doors); and at Sfax. Also a well known ribat or fortified military monastery was built at Monastir, and another at Susa (in 821 by Ziyadat Allah I); here Islamic warriors were trained.
In 831 Ziyadat Allah I (r. 817-838), son of the founder Ibrahim, launched an invasion of Sicily. Placed in command was Asad ibn al-Furat, the qadi or religious judge; the military adventure was termed a jihad. This expedition proved successful; Palermo was made the capitol of the region captured. Later raids were made against the Italian peninsula; in 846 Rome was attacked and the Basilica of St. Peter sacked. In orchestrating the invasion of Sicily, the Aghlabid rulers had managed to unite two rebellious factions (the army and the clergy) in a common effort against outsiders. Later Islamic rulers in Sicily severed connections with Ifriqiyah, and their own Sicilian Kalbid dynasty (948-1053) governed the now independent Emirate.
The invasion of Sicily had worked to stabilize the political order in Ifriqiya, which progressed in relative tranquility during its middle period. In its final decline, however, the dynasty self-destructed, in that its eleventh and last amir, Ziyadat Allah III (r. 902-909) (d. 916), due to insecurity stemming from his father's assassination, ordered his rival brothers and uncles executed. This occurred during the assaults made by the newly emergent Fatimids (see below) against the Aghlabid domains

### Institutions and society

In the Aghlabid government generally, the high positions were filled by "princes of the blood, whose loyalty could be relied on." The judicial post of Qadi of Kairouan was said to be given "only to outstanding personalities notable for their conscientiousness even more than their knowledge." On the other hand, the administrative staffs were composed of dependent clients (mostly recent Arab and Persian immigrants), and the local bilingual Afariq (mostly Berber, and which included many Christians). The Islamic state in Ifriqiya paralleled in many respects the government structure formed in Abbasid Baghdad. Aghlabid offices included the vizier [prime minister], the hajib [chamberlain], the sahib al-barid [master of posts and intelligence], and numerous kuttab [secretaries] (e.g., of taxation, of the mint, of the army, of correspondence). Leading Jews formed a small elite group. As in an earlier periods (e.g., under Byzantine rule), the majority of the population consisted of rural Berbers, distrusted now because of Kharajite or similar rebel tendencies.
Kairouan (or Qayrawan) had become the cultural center of not only of Ifriqiya but of the entire Maghrib. A type of volume then current, the tabaqat (concerned with the handling of documents), indirectly illuminates elite life in Aghlabid Ifriqiya. One such work was the Tabaqat 'ulama' Ifriqiya [Classes of Scholars of Ifriqiya] written by Abu al-'Arab. Among the Sunni Muslim ulema, two learned professions then came to the fore: (a) the faqih (plural fuqaha) or the jurist; and (b) the 'ābid or the ascetics.
The fuqaha congregated at Kairouan, then the legal center of the entire al-Maghrib. The more liberal Hanafi school of Muslim law at first predominated in Ifriqiyah. Soon, however, a strict form of the Maliki school came to prevail, which in fact became the only widespread madhhab, not only in Kairouan, but throughout North Africa. The Maliki school of law persisted (despite several major interruptions) in being the legal norm throughout the Maghrib and continues so today.
The Maliki madhhab was introduced to Ifriqiya by the jurist Asad ibn al-Furat (759-829), yet he was known to waver somewhat between the prior Hanafi and the Maliki. The influential law book called Mudawanna, written by his disciple Sahnun ('Abd al-Salam b. Sa'id) (776-854), provided a "vulgate of North-African Malikism" for practical use during the period when Maliki legal doctrines won the field against its rival, the Hanafi. Abu Hanifa (700-767) (founder of the Hanafi school) drew out fiqh that was perhaps better suited to its origin in Baghdad, a sophisticated imperial capital; while Malik ibn Anas (716-795) initiated the school bearing his name in the smaller, rural city of Medina. By choosing the then more marginal Maliki school, the jurists of Kairouan probably obtained more discretion in defining Maghriban legal culture.
The Maliki jurists were often at odds with the Aghlabids, over the Arab rulers' disappointing personal moral conduct, and over the fiscal issue of taxation of agriculture (i.e., of a new fixed cash levy replacing the orthodox tithe in kind). The offending tax on crops payable in cash being the act of the second amir, 'Abdullah ibn Ibrahim (812-817). Further, the Maliki fuqaha was commonly understood to act more in favor of local autonomy, hence in the interests of the Berbers, by blocking potential intrusions into Ifriqiya affairs and filtering out foreign influence, which might originate from the central Arab power in the East.
Besides jurists there was a second community of Muslim ulema, the scholars and ascetics. Foremost among these ābid was Buhlul b. Rashid (d. 799), who reputedly despised money and refused the post of grand judge; his fame accordingly spread throughout the Islamic world. By virtue of their piety and independence, the ābid won social prestige and a voice in politics; some scholars would speak on behalf of the governed cities, criticizing the regime's finance and trade decisions. Although substantially different, the status of the ābid relates somewhat to the much later, largely Berber figure of the Maghribi saint, the wali, who as keeper of baraka (spiritual charisma) became the object of veneration by religious believers, and whose tomb would be the destination of pilgrimage.
Economically, Ifriqiya flourished under Aghlabid rule. Extensive improvements were made to the pre-existing water works in order to promote olive groves and other agriculture (oils and cereals were exported), to irrigate the royal gardens, and for livestock. Roman aqueducts to supply the towns with water were rebuilt under Abu Ibrahim Ahmad, the sixth amir. In the Kairouan region hundreds of basins were constructed to store water for the raising of horses.
Commercial trade resumed under the new Islamic regime, e.g., by sea, particularly to the east with the Egyptian port of Alexandria as a primary destination. Also, improved trade routes linked Ifriqiya with the continental interior, the Sahara and the Sudan, regions regularly incorporated into the Mediterranean commerce for the first time during this period. Evidently camels on a large scale had not been common to these arid regions until the fourth century, and it was not until several centuries later that their use in the Saharan trade became common. Now this long-distance overland trade began in earnest. The desert city of Sijilmasa near the Atlas mountains in the far west [maghrib al-aqsa] served as one of the primary trading junctions and entrepôts, e.g., for salt and gold. Regarding Ifriqiya, Wargla was the primary desert contact for Gafsa and more distant Kairouan. In addition, Ghadames, Ghat, and Tuat served as stops for the Saharan trade to Aghlabid Ifriqiya.
A prosperous economy permitted a refined and luxurious court life and the construction of the new palace cities of al-'Abbasiya (809), and Raqada (877), where were situated the new residences of the ruling emir. The architecture of Ifriqiya was later imitated further west in Fez, Tlemcen, and Bougie. The location of these palace cities for Aghlabid government was purposely outside of the sway of Kairouan, which city had become dominated by Muslim clerical institutions, which were independent of emir's control. Yet generally Ifriqiyah during the era under the Aghlabid Dynasty (799-909) for the most part continued its leading rôle in the region, in the newly installed Muslim Maghrib, due generally to its peace and stability, recognized cultural achievements, and material prosperity.

## Independent Berber Islam
### Kharijite revolt

The origins of the Rustamid state can be traced to the Berber Kharijite (Ar: Khawarij) revolt (739-772) against the new Arab Sunni power that was being established across North Africa following the Islamic conquest. Originating in Mesopotamia, the Kharijite movement had begun in protest against the fourth caliph Ali, who consented to negotiate during a Muslim civil war (656-661) despite his superior army in the field; as a result some of his armed forces left the camp, hence the movement of the Khawarij ["those who go out"]. Originally puritan in outlook, being of the ummah of Islam for a believer indicated a perfection of the soul, yet sin constituted a schism, a split from other believers, the sinner becoming an apostate. The leader must be above reproach, yet could be non-Arab. Never attaining lasting success, but persisting in its struggles, the Kharijite movement remains today only in its Ibadi branch, with small minorities in isolated locales throughout the Muslim world. The Ibadis predominate in Oman.
In the Maghrib the un-Islamic tax policies imposed on the Muslim Berbers by the new Arab Islamic regime (levying the kharaj [land tax] and the jizya [poll tax] meant only for infidels) provoked a widespread armed resistance, which came to be led by Kharijite Berbers. The widespread struggle of this movement included victories, e.g., the "battle of the nobles" in 740. Later the Kharijites became divided and eventually were defeated after some decades. Arab historians remark that the 772 defeat of the Kharijite Berbers by an Abbasid army in battle near Tripoli was "the last of 375 battles" the Berbers had fought for their rights against armies from the East. Yet the Kharijites persisted under the Rustamids. Even until today across North Africa they practice still, small island communities of this religious minority within Islam.

### Rustamid kingdom

A Kharijite remnant established a state (776–909) under the Rustamids, whose capital was at Tahert (located in the mountains southwest of modern Algiers). Apart from the lands surrounding Tahert, Rustamid territory consisted of largely the upland steppe or "pre-Sahara" that forms the frontier between the better watered coastal regions of the Maghrib and the arid Sahara desert. As such, its territory extended in a narrow climatic strip eastward as far as Tripolitania and Jebel Nefusa (in modern Libya). In between lay southern Ifriqiya, where Rustamid lands included the oases of the Djerid, with its chotts (salt lakes), and the island of Djerba. The functionality of this elongated geography may be explained by the liberal nature of the Rustamid government: "[T]he imam did not so much rule or govern the surrounding tribes as preside over them, his authority being recognized rather than imposed and his mediation in disputes willingly sought." As such this Rustamids territory ran from Tlemcen in the west to Jebel Nefusa in the east.
The peoples of this climatic zone of the pre-Sahara began to be called the Arzuges in the 3rd century by the Roman legio III Augusta of Africa province. The Roman military authorities insulated Arzugitana from rule by the coastal cities. The fall of Rome "offered unprecedented opportunities for the communities of the pre-Sahara zone and their political elites, and may be seen as a period of renaissance in the region, at least in the political sphere." The Arzuges managed to recover their autonomy.
   "Subsequently neither the Vandal monarchy nor the East Roman exarchate appear to have re-established direct rule over the Tripolitanian hinterland. Instead the communities of the pre-desert wadis and Jebel ranges may have been absorbed in a larger tribal confederation variously labeled the Laguatan, Levathae or, in the Arabic sources, the Lawata.
   "The existence of labels such as Gaetuli and Arzuges thus reflects a longstanding and distinct sense of identity amongst the inhabitants of the pre-Saharan zone, which probably underwent a revival in late Antiquity. The support for the Ibadi movement shown by the communities of the Jebel Nefusa and the Jerid oases in the heart of the former Arzugitana suggests that this regional sense of identity and consequent desire for autonomy were maintained into the early medieval period and acquired a new emblematic marker in the adoption of the Ibadi faith. Indeed Savage suggests that many of the 'tribal' groups which figure in the sources in this period, notably the Nefusa, may represent alliances of disparate communities which coalesced at this very time in response to the catalyst provided by the egalitarian Ibadi message and were retrospectively legitimized with a genealogical tribal framework."
The Arab Aghlabid emirate in Ifriqiya remained the dominant state in the region, and the Rustamid's neighbors. Nonetheless the Aghlabids proved unable to dislodge these remnant Kharijites. Soon they were obliged to recognize Rustamid rule in the pre-Sahara region of the eastern Maghrib. In Hispania now transformed into al-Andalus, the Emirs of Córdoba welcomed the presence of the Rustamids Berbers as natural allies against the Aghlabids, whom Umayyad Córdoba considered Abbasid agents.
Tahert was economically well situated, as it formed an entrepot for trade between the Mediterranean coastlands and the Sahara. During the summer Tahert became the market place where the pastoralist of the desert and steppe exchanged their animal produce for the local grains harvested by sedentary farmers. As the most prominent Khawarij center, it attracted immigrants from across the Islamic world, including Persia the home of its founder. Christians also found welcome. Yet in another sense behavioral tolerance was slim; "life at Tahert was conducted in a permanent state of religious fevor."
The founder Ibn Rustam (r. 776–784) took the title of Imam. While in theory elected by elders, in practice the Imam was an hereditary office. The constitution was theocratic. The Imam was both a political and a religious leader. Islamic law was strictly applied. "[A]dulterers were stoned, the hands of thieves were cut off, and in war pillage and the massacring of non-warriors were not permitted." The Imam managed the state, law and justice, prayers, and charity. He collected zakah ["alms"] at harvest and distributed it to the poor and for public works. He appointed the qadi (judge), the treasurer, and the police chief. The Imam was expected to lead an ascetic life and be an able theologian. He was also expected to be astute, as civic conflicts might develop into religious schism. Yet opposing parties in disputes often submitted the matter to mediation. The Khawarij remained tolerant toward "unbelievers".
The remaining Christians of the region (called Afariqa or Ajam by Muslim Arabs) could find a tolerant home in Rustamid Tahert, where their community was known as the Majjana. This acceptance "might explain the growth of Ibadi communities in area where there is also evidence for the persistence of Christianity." Yet here, given the continuing defense of Rustamid autonomy against "the depredations of the central power" the Aghlabids, the choice to convert to Islam was sometimes "as much a political as a religious act."
The Rustamids endured about as long at the Aghlibid emirate; both states declined, and fell to the Fatimids during 909. Kharijites surviving from the Rustamid era eventually became Ibadis. For the most part, they now reside in the Djebel Nefousa (western Libya), in the Mzab and at Wargla (eastern Algeria), and on Djerba island in Tunisia.

## Fatimids: Shi'a caliphate

In the far west of Ifriqiya, the newly emerging Fatimid movement grew in strength and numbers. Thereafter the Fatimids began to launch frequent attacks on the Aghlabid regime. Such militant aggression provoked general unrest and increased Aghlabid political instability. The Fatimids eventually managed to capture Kairouan in 909, forcing the last of the Aghlabid line, Ziyadat Allah III, to evacuate the palace at Raqadda. Concurrently the Rustamid state was overthrown. On the east coast of Ifriqiaya facing Egypt, the Fatimids built a new capital on top of ancient ruins, calling the seaport Mahdiya after their mahdi.

### Maghribi origin

The Fatimid movement had originated locally in al-Maghrib, based on the strength of the Kotama Berbers in Kabylia (Setif, south of Bougie, eastern Algeria). The two founders of the movement were recent immigrants from the Islamic east: Abu 'Abdulla ash-Shi'i, originally from San'a in Yemen; and, arriving from Salamiyah in Syria, 'Ubaidalla Sa'id. These two were religious dissidents who had come west to al-Magrib specifically to propagate their beliefs. The later, 'Ubaidalla Sa'id, claimed descent from Fatimah the daughter of Muhammad; he was to proclaim himself the Fatimid Mahdi. Their religious affiliation was the Ismaili branch of the Shia.
By agreement, the first of the two founders to arrive (circa 893) was Abu 'Abdulla ash-Shi'i, the Ismaili Da'i or propagandist. He found welcome in the hostility against the Caliphate in Baghdad freely expressed by the Kotama Berbers. After his success in recruitment and in building the organization, Abu 'Abdulla was ready in 902 to send for 'Ubaidalla Sa'ed, who (after adventures and Aghlibid imprisonment in Sijilmasa) arrived in 910. 'Ubaidall Sa'ed then proclaimed himself Mahdi, literally "the guided one", an august Islamic title of supreme command, taking the name Ubayd Allah al-Mahdi Billah. He assumed leadership of the movement. Thereafter Abu 'Abdulla was killed in a dispute over control.
From the start the Shi'a Fatimid movement had been focused on expansion eastward toward the heartland of Islam. Soon the new Mahdi ordered an attack on Egypt by a Fatimid army of Kotama Berbers led by his son al-Qa'im, once in 914, and again in 919; the Fatimids quickly took Alexandria, but both times lost it to the Sunni Abbasids. Probing for weakness, the Mahdi then sent an invasion westward, but his forces met with mixed results. Many Sunnis, including the Umayyad Caliph of al-Andalus and the Zenata Berber kingdom in Morocco, effectively opposed him because of his Ismaili Shi'a affiliation. The Mahdi did not follow Maliki law; he taxed harshly, incurring further resentment. His capital Mahdiya was more a fort than a princely city. The Maghrib was disrupted, being contested between the Zenata in the west and the Sanhaja who favored the Fatimids. Yet eventually Fatimid authority spread to most of al-Maghrib.
After the death of the Mahdi, there came the popular Kharijite revolt of 935, under Abu Yazid (nicknamed Abu Himara, "the man on a donkey"). Abu Yazid was known to ride about clad in common clothes accompanied by his wife and four sons. This Berber revolt, centering on a social justice appeal with respect to Kharijite ideals, gathered a wide following; by 943 it was said to be spreading confusion far and wide. The Mahdi's son, the Fatimid caliph al-Qa'im, became besieged in his capital Mahdiya. The situation appeared desperate when a relief column led by Ziri ibn Manad broke through the siege with supplies and reinforcements for the Fatimids. Eventually Abu Yazid lost much of his following and in 946 was defeated in battle; this was the work of the son of al-Qa'im, the next Fatimid caliph, Ishmail, who accordingly took the sobriquet Mansur, the "victor". Mansur then moved his residence and his government to Kairouan. Fatimid rule continued to be under attack by Sunni power to the west, i.e., the Umayyad Caliphate in Al-Andalus. Nonetheless the Fatimids prospered.

### Conquest of Egypt

In 969 the Fatimid caliph al-Mu'izz sent against Egypt his best general Jawhar al-Rumi, who led a Kotama Berber army. Egypt then was nominally under the Abbasid Caliphate, yet since 856 Egypt had been ruled by Turks, now by the Turkish Ikhshidid dynasty; however, actual control had passed into the strong hands of the Ethiopian eunuch Abu-l-Misk Kafur for 22 years. At Kafur's death in 968, Egypt's leadership became weak and confused. The Fatimids in Ifriqiya, carefully observing these conditions in Misr (Egypt), ceased the opportunity to conquer.
Jawhar al-Rumi accordingly managed the military conquest without great difficulty. The Shi'a Fatimids subsequently founded al-Qahira (Cairo) ["the victorious" or the "city of Mars"]. In 970 the Fatimids also founded the world-famous al-Azhar mosque, which later became the leading Sunni theological center. Three years later al-Mu'izz the Fatimid caliph decided to leave Ifriqiyah for Egypt, which he did, taking everything, "his treasures, his administrative staff, and the coffins of his predecessors." This al-Mu'izz was highly educated, wrote Arabic poetry, had mastered Berber, studied Greek, and delighted in literature; he was also a very capable ruler and it was he who founded Fatimid power in Egypt. Once centered there the Fatimids expanded their possessions further, northeast to Syria and southeast to Mecca and Medina, while retaining control of North Africa until the late 11th century. From Cairo the Fatimids were to enjoy relative success, even with the loss of Ifriqiya, reigning until 1171. They became for a time the foremost power of Islam; they never returned to Ifriqiyah. Meanwhile, the Kotama Berbers, wornout from their conflicts on behalf of the Fatimids, disappeared from the streets of al-Qahira, and thereafter also from the life of al-Maghrib.
The western lands of the Fatimids were assigned to Berber vassals who continued in name the Shi'a caliphate rule. The first chosen ruler was Buluggin ibn Ziri, son of Ziri ibn Manad (died 971), the Sanhaja Berber chieftain who had saved the Fatimids when besieged in Mahdiya by Abu Yazid (see above). The Zirid dynasty would eventually become the sovereign power in Ifriqiya.