Habib ibn Abd al-Rahman al-Fihri (? – May/June, 757) was an Arab noble of the Oqbid or Fihrid family, and briefly ruler of Ifriqiya (North Africa) from 755 to 757.
Habib ibn Abd al-Rahman was the son and designated heir of Ifriqiyan strongman and ruler Abd al-Rahman ibn Habib al-Fihri, who had ruled Ifriqiya semi-independently since 745. Habib had served as wali in Barqa (Cyrenaica) on his father's behalf.
In 755, in a palace coup, the emir Abd al-Rahman ibn Habib was murdered by his brothers Ilyas ibn Habib and Abd al-Wareth ibn Habib. Ilyas promptly proclaimed himself ruler of Ifriqiya. The young Habib fled Kairouan and took refuge in Tunis with his uncle Amran ibn Habib, who was appalled at the fratricide.
Amran helped Habib raise an army to avenge his father's murder. The armies met south of Tunis in late 755, but before battle was enjoined, an agreement was reached to partition Ifriqiya between the Fihrids. Amran was to be assigned the government of Tunis and environs, the young Habib the government of southerly Gafsa and Nefzoua, leaving Ilyas with Kairouan and the remainder of Ifriqiya. The settlement made, Habib proceeded to Kairouan, while Ilyas accompanied Amran back to Tunis. But once in Tunis, Ilyas suddenly ordered the arrest of Amran and his coterie and dispatched them in chains to al-Andalus.
Ilyas then bore down on Kairouan and pressured the young Habib to agree to depart for al-Andalus. A ship was outfitted, and even set out, but was forced back to port by contrary winds. During this farcical interlude, Habib was seized by partisans of his late father Abd al-Rahman, who promptly proclaimed Habib emir of Ifriqiya and raised an army in his name.
The two armies met in the environs of Laribus. But before battle was enjoined, Habib challenged Ilyas to solve the quarrel in single combat. At first hesitant, Ilyas finally consented, at the urging of his own commanders. Habib defeated and killed Ilyas, carrying his head as a trophy in a procession back to Kairouan. This took place in December 755.
Hearing of Ilyas's defeat, Abd al-Wareth and remaining partisans of Ilyas fled south and took shelter among the Warfajuma Berbers. A sub-tribe of the Nafzawa, the Warfajuma had been fired up by Kharijite (Sufrites) and broken away during the Great Berber Revolt of 740s. Abd al-Wareth set about plotting with their chieftain Asim ibn Jamil al-Warfajumi to take power in Kairouan and depose his nephew Habib. To rally support to their arms, the rebels declared for the Abbasid caliph Al-Mansur.
In 756-57, heeding the danger, Habib ibn Abd al-Rahman set out south against the Warfajuma, leaving the qadi Abu Quraib in charge of Kairouan. But the Ifriqiyan army was roundly defeated by the Berber rebels. Habib proceeded to take shelter in Gabès and appealed to Abu Quraib to dispatch reinforcements from Kairouan. But these were intercepted by the Berber force and, hearing the rebels had declared for the Abbasids, decided to switch over to them.
In early 757, the Warfajjuma under Asim ibn Jamil, marching under the black banner of the Abbasids, entered Kairouan unopposed. The Fihrid Abd al-Wareth disappears from the chronicles around this time. Habib, who was forced out of Gabès, and regathered his forces in the Aures hills and made a dash to recover Kairouan but was defeated and killed by the Berbers in the outskirts of the city in May–June, 757.
What happened in the aftermath has been much debated. It is alleged by Arab chroniclers that upon seizing the city, the Warfajuma Berbers, possessed by a fanatical (Sufrite) Kharijite fervor, set about plundering the city of Kairouan and undertaking great massacres of the civil population (the radical Sufrite brand of Kharijitism sported by the Warfajuma leaders regarded all non-Kharijites as outright apostates deserving death).
In the meantime, profiting from the Fihrid family quarrel, the Ibadites that Abd al-Rahman ibn Habib had driven into the Tripolitan hills of Jebel Nafusa in 752 mounted a comeback. Rallied by their new imam Abu al-Khattab al-Ma'afiri, the Ibadites seized Tripoli sometime in 757. Although also a Kharijite sect, the Ibadites were considerably less fanatical than the Sufrites and were horrified to hear of the massacres in Kairouan. In 758, the Ibadites set out to defeat the Warfajuma and capture Kairouan, putting an end to the Sufrite terror and establishing an (Ibadite) Kharijite imamate over Ifriqiya.