The birth of Islam in Arabia in the early 7C took the world by storm. After the death of the Prophet Muhammad in 632, his followers set out to conquer North Africa in the name of Islam. The Arabs arrived in Tunisia in 670, founding a new city inland at Kairouan. From here they were determined to conquer Ifriqiya, their name for central North Africa. They met fierce resistance from the Berbers, and the Byzantines held on to Carthage until 698. That same year El Kahina, the warrior Berber queen who won several victories against the Arabs, was killed at Tabarka. With the last serious opposition out of the way, the Arabs set about fortifying the small settlement of Tunis as their new capital.
By the early 8C, many Berbers had converted to the new religion. But the Arab caliph (ruler) in Baghdad could not control all the schisms and rebellions within his huge empire. When Ibrahim ibn al Aghlab restored order after a rebellion in Tunis in 797, he founded a dynasty which ruled over North Africa in the name of the caliphs until 909.
The era of Aghlabid rule was a golden age for Tunisia. The Great Mosque was built at Tunis, as well as several ribats (fortified monasteries) along the coast. Agriculture and trade were revived. But hostility grew over religious doctrine, class divisions and the decadence of the last Aghlabid rulers. In 909 they were deposed by the Fatimids, a strict Shi’ite sect whose leader Ubaydalla Said claimed to be descended from the Prophet’s daughter(the majority of Tunisians were Sunni Muslims).
The Fatimids had grand ambitions. After establishing a fortress city at Mahdia, they went on to conquer Sicily in 912 and all of Egypt by 969, moving their capital to Cairo soon after. Tunisia fell into anarchy and decline, making an easy target for Roger II, Norman king of Sicily, in the 12C. After he had seized several coastal towns, the Almohads from Morocco came to the rescue, unifying the Maghreb (North Africa) under a single rule.
In 1230 Abu Zakariyya, the Almohad governor of Tunisia, declared independence from Marrakesh, establishing the Hafsid dynasty which ruled Tunisia for 300 years. His son, El Mustansir, was recognised as caliph. His capital, Tunis, prospered as the rich trade with the Sahara, the Sudan and, increasingly, Europe was channeled through the country. The first palace was built on the site of the Bardo museum, and the city grew as new districts were built for European merchants and Muslim migrants from Spain.
Although the Pope had not earmarked Tunisia as a destination on the Crusade trail, Louis IX of France, later canonized St Louis, landed at Carthage with an army of Crusaders in 1270. He was largely motivated by debts owed to French traders, including his brother Charles, king of Sicily. Louis’s sudden death from dysentery saved the Hafsids from defeat and peace was negotiated.
After El Mustansir’s death in 1277, Tunisia was riven by conflicts with the Berber tribes, with rival sultans and between Spanish Christians who tried to establish outposts. Despite their weakening power, the Hafsids held out until 1574.