Abbasid conquest of Ifriqiya

The Abbasid conquest of Ifriqiya was an armed campaign in 761 against Kharijite Ibadites in Ifriqiya (present-day Tunisia, eastern Algeria and Tripolitania) led by Muhammad ibn al-Ash'ath al-Khuza'i on behalf of the Abbasid Caliphate. By the end of the campaign, the Abbasids brought the political domination of the Ibadites in Ifriqiya to an end, and recovered Abbasid authority in the Maghreb as far as eastern Algeria.

Background
Umayyad rule in the Maghreb came to an end in 747 once the Fihrids, descendants of Uqba ibn Nafi, seized power in Ifriqiya while taking advantage of the Abbasid Revolution against the Umayyad Caliphate. The Fihrids controlled all of Tunisia, excluding the southern parts that were under the influence of the Warfajuma Berber tribe, who were associated with the Sufri Kharijites.

Fihrid rule collapsed in 756 when the Warfajuma successfully conquered northern Ifriqiya and captured Kairouan. Immediately afterward, the Ibadiyyah in Tripolitania proclaimed one of their religious leaders as the imam, and conquered Tunisia from the Sufrids in 758. This led to the formation of an Ibadi state, stretching from Tunisia to Tripolitania, which existed until 761 when the Abbasids conquered the region after having consolidated their authority as caliphs in the Middle East.

Campaign
From 759, the Abbasid Caliphate set out to recover the Maghreb for the empire. Once the caliph, Abu Ja'far al-Mansur, has dealt with his internal problems in the Mashriq, he shifted his focus to the Maghreb. He appointed Muhammad ibn al-Ash'ath al-Khuza'i as governor of Egypt and the Maghreb, and ordered him to suppress the Kharijite rebellion in Ifriqiya. Ibn al-Ash'ath initially sent two armies which were both defeated by the Ibadites. Ibn al-Ash'ath then took command of an army and defeated the Ibadites in the battle of Tawargha (near Misrata, Libya), killing the Ibadi Imam Abu al-Khattab al-Mu'afiri and many of his followers. Ibn al-Ash'ath then marched on Ifriqiya, capturing Kairouan in 761 where he forced the governor, Abd al-Rahman ibn Rustum, to flee to the mountains located south of Oran. Rustum fled westwards and established a new capital at Tahert (present-day Algeria). This campaign brought an end to the political domination of the Ibadites in Ifriqiya and established Abbasid direct authority there. The Zab in eastern Algeria constituted the western limit of the area held by the Abbasid governors, where the Abbasids had an important military base at Tubna. To the west of this territory were the Rustamids, Midrarids and Idrisids. After 800, the Abbasids only held nominal authority in Ifriqiya, as the wilayah (province) became an autonomous principality ruled by the Arab dynasty of the Aghlabids until 909.