The Zirids were Sanhaja Berbers originating from the area of modern Algeria. In the 10th century this tribe served as vassals of the Fatimid Caliphate, defeating the Kharijite rebellion of Abu Yazid (943-947), under Ziri ibn Manad (935-971). Ziri was installed as the governor of central Maghreb and founded the gubernatorial residence of Ashir south-east of Algiers, with Fatimid support.
When the Fatimids moved their capital to Egypt in 972, Ziri's son Buluggin ibn Ziri (971-984) was appointed viceroy of Ifriqiya. The removal of the fleet to Egypt made the retention of Kalbid Sicily impossible, while Algeria broke away under the governorship of Hammad ibn Buluggin, Buluggin's son.
The Zirid realm (dark green) after the secession of the Hammadids
(1018) and before the influx of Banu Hilal
The relationship with their Fatimid overlords varied - in 1016 thousands of Shiites lost their lives in rebellions in Ifriqiya, and the Fatimids encouraged the defection of Tripolitania from the Zirids, but nevertheless the relationship remained close. In 1049 the Zirids broke away completely by adopting Sunni Islam and recognizing the Abbasids of Baghdad as rightful Caliphs, a move which was popular with the urban Arabs of Kairouan.
The Zirid period of Tunisia is considered a high point in its history, with agriculture, industry, trade and learning, both religious and secular, all flourishing, especially in their capital, Kairouan. Management of the area by later Zirid rulers was neglectful as the agricultural economy declined, prompting an increase in banditry among the rural population.
When the Zirids renounced Shia Islam and recognized the Abbasid Caliphate in 1048, the Fatimids sent the Arab tribes of the Banu Hilal and the Banu Sulaym to Ifriqiya. The Zirids were defeated, and the land laid waste by the Bedouin conquerors. The resulting anarchy devastated the previously flourishing agriculture, and the coastal towns assumed a new importance as conduits for maritime trade and bases for piracy against Christian shipping, as well as being the last holdout of the Zirids.
After the loss of Kairouan (1057) the rule of the Zirids was limited to a coastal strip with Mahdia as the capital, while several Bedouin Emirates formed inland. Between 1146 and 1148 the Normans of Sicily conquered all the coastal towns, and in 1152 the last Zirids in Algeria were superseded by the Almohad Caliphate.