Foundation and early Islamic period The foundation of Kairouan dates to about the year 670 when the
Arab general
Uqba ibn Nafi of
Caliph Mu'awiya selected a site in the middle of a dense forest, then infested with wild beasts and reptiles, as the location of a military post for the conquest of
the West. Formerly, the city of Kamounia was located where Kairouan now stands. It had housed a Byzantine garrison before the Arab conquest, and stood far from the sea – safe from the continued attacks of the
Berbers who had fiercely resisted the Arab invasion. Berber resistance continued, led first by
Kusaila, whose troops killed Uqba at
Biskra about fifteen years after the establishment of the military post, and then by a Berber woman called
Al-Kahina who was killed and her army defeated in 702. Subsequently, there occurred a mass conversion of the
Berbers to Islam.
Kharijites or Islamic "outsiders" who formed an egalitarian and puritanical sect appeared and are still present on the island of
Djerba. In October 741, in the course of the
Great Berber Revolt in the
Maghreb, the
Ifriqiyan army, along with a Syrian force dispatched by the caliph, was destroyed by the Berbers at the
Battle of Bagdoura. The governor
Kulthum ibn Iyad al-Qasi perished in the field, his nephew and successor
Balj ibn Bishr al-Qushayri was holed up with the remnant of the army in
Spain, leaving the whole of Ifriqiya open to the advance of the Berber rebels. Not having any more forces at his disposal, the
Umayyad Caliph
Hisham quickly appointed Handhala ibn Safwan as governor of Ifriqiya, with supervisory authority over all the
Maghreb (North Africa west of Egypt) and
al-Andalus (Spain), and instructed him to take whatever forces he could gather to defend Ifriqiya and quash the Berber rebellion. Leaving Egypt in the hand of
Hafs ibn al-Walid ibn Yusuf al-Hadrami, Handhala set out westwards in February 742, picking up additional forces from
Barqa (Cyrenaica) and
Tripoli (Tripolitana). He arrived in Kairouan around April, 742. The
qadi of Ifriqiya,
Abd al-Rahman ibn Oqba al-Ghaffari, had been managing the defense of Kairouan, and succeeded in fending off an attack by the Berber rebel army raised in southern Tunisia by the
Sufrite leader
Oqasha ibn Ayub al-Fezari. Handhala ibn Safwan arrived in Kairouan just as Oqasha was said to be mounting a new attack, in coordination with another large Berber army coming in from the west, led by
Abd al-Wahid ibn Yazid al-Hawwari. The Berber rebel armies were to make junction in front of Kairouan, before launching their final attack on the city. Wasting no time, Handhala dispatched a cavalry force to slow down Abd al-Wahid's progress, and threw the bulk of his forces south, defeating Oqasha in a bloody battle at
El-Qarn and taking him prisoner. But Handhala had taken a lot of losses himself, and now faced the unhappy prospect of Abd al-Wahid's gigantic army, said to be some 300,000, ostensibly the largest Berber army ever seen. Hurrying back, Handhala is said to have put the entire population of Kairouan under arms to bolster his ranks, before setting out again. In perhaps the bloodiest encounter in the Berber wars, Handhala ibn Safwan defeated the great Berber army of Abd al-Wahid ibn Yazid at
al-Asnam in May 742 (perhaps a little later), just three miles outside of Kairouan. Some 120,000–180,000 Berbers, including Abd al-Wahid, fell in the field of battle in that single encounter.
Aghlabid period In 745,
Kharijite Berbers captured Kairouan, which was already at that time a developed city with luxuriant gardens and olive groves. Power struggles continued until
Ibrahim ibn al-Aghlab recaptured Kairouan at the end of the 8th century. In 800
Caliph Harun ar-Rashid in
Baghdad confirmed Ibrahim as
emir and hereditary ruler of Ifriqiya. Ibrahim ibn al-Aghlab founded the
Aghlabid dynasty which ruled Ifriqiya between 800 and 909. The new emirs embellished Kairouan and made it their capital. It soon became famous for its wealth and prosperity, reaching the levels of
Basra and
Kufa and giving Tunisia a period of power and prosperity. The Aghlabids built the great mosque and established in it a university that was a centre of education both in Islamic thought and in the secular sciences. Its role can be compared to that of the
University of Paris in the
Middle Ages. In the 9th century, the city became a brilliant focus of Arab and Islamic cultures attracting scholars from all over the
Islamic World. In that period
Imam Sahnun and
Asad ibn al-Furat made of Kairouan a temple of knowledge and a magnificent centre of diffusion of Islamic sciences. The Aghlabids also built palaces, fortifications and fine waterworks of which only the pools remain. From Kairouan envoys from
Charlemagne and the
Holy Roman Empire returned with glowing reports of the Aghlabid palaces, libraries and gardens – and from the crippling taxation imposed to pay for their drunkenness and sundry debaucheries. The Aghlabids also pacified the country and conquered Sicily in 827.
Fatimid and Zirid period , minted in Kairouan in 912 CEIn 893, through the mission of
Abdullah al Mahdi, the
Kutama Berbers from the west of the country started the movement of the
Shiite Fatimids. The year 909 saw the overthrow of the
Sunni Aghlabids who ruled Ifriqiya and the establishment of the Fatimid dynasty. During the rule of the Fatimids, Kairouan was neglected and lost its importance: the new rulers resided first in
Raqqada but soon moved their capital to the newly built
Al Mahdiyah on the eastern coast of Tunisia. After succeeding in extending their rule over all of central
Maghreb, an area consisting of the modern countries of
Morocco,
Algeria,
Tunisia and
Libya, they eventually moved east to
Egypt to found
Cairo making it the capital of their vast Caliphate and leaving the
Zirids as their vassals in Ifriqiya. Governing again from Kairouan, the Zirids led the country through another artistic, commercial and agricultural heyday. Schools and universities flourished, overseas trade in local manufactures and farm produce ran high and the courts of the Zirids rulers were centres of refinement that eclipsed those of their European contemporaries. When the Zirids declared their independence from Cairo and their conversion to Sunni Islam in 1045 by giving allegiance to
Baghdad, the Fatimid Caliph
Ma'ad al-Mustansir Billah sent as punishment hordes of troublesome Arab tribes (
Banu Hilal and
Banu Sulaym) to invade Ifriqiya. These invaders so utterly captured Kairouan from the Zirids in 1057 and destroyed it that it never regained its former importance and their influx was a major factor in the spread of nomadism in areas where agriculture had previously been dominant. Some 1,700 years of intermittent but continual progress was undone within a decade as in most part of the country the land was laid to waste for nearly two centuries.
Later history Al-Idrisi described the city in the 12th century:The city of Kairouan is the mother of settlements and the capital of regions. It was once the greatest city of the West in its expanse, the most populous, the wealthiest, the most prosperous, the most finely built, and the most ambitious, with the most profitable trade, the highest tax revenues, the most flourishing markets, and the greatest commercial gains, while its people were also the most rebellious and the most arrogant of the ignorant, yet among its virtuous elite, the dominant qualities were adherence to righteousness, fulfillment of covenants, avoidance of doubtful matters, abstention from prohibitions, mastery of refined sciences, and an inclination toward moderation. But God Almighty afflicted it with the Arabs, and calamities befell it one after another, until nothing remained of it but fading ruins and obliterated traces. In our present time, only a portion of it is enclosed by an earthen wall. Its rulers are Arabs, who collect whatever revenues remain. A few people still reside there, engaged in modest trade with meager benefits. Scholars speculate that it will soon return to its former state of prosperity and grandeur. Its water supply is scarce, and its inhabitants drink from the great cistern (majel) within the city. This cistern is an architectural marvel, as it is built in a square shape with a tower-like structure rising in the center. Each side measures two hundred cubits, and it remains filled with water. Kairouan was originally two cities: one was Kairouan itself, and the other was
Sabra. Sabra was the royal residence, and at the height of its prosperity, it contained three hundred baths—most of them private, while the rest were public for all people. Sabra, however, is now in complete ruin, devoid of any inhabitants. In the 13th century under the prosperous
Hafsids dynasty that ruled Ifriqiya, the city started to emerge from its ruins. It is only under the
Husainid Dynasty that Kairouan started to find an honorable place in the country and throughout the Islamic world. In 1881, Kairouan was taken by the French, after which non-Muslims were allowed access to the city. The French built the
Sousse–Kairouan Decauville railway, which operated from 1882 to 1996, before it was regauged to gauge. The old city of Kairouan and its associated historic monuments became a UNESCO World Heritage Site in 1988. In December 2023, about 30m of wall near the Gate of the Leather Workers collapsed during restoration. Three masons were killed, and several others injured. ==Geography==