 When the latter were ousted from Iraq by the Umayyads in 691, al-Muhallab switched allegiance to the Umayyad caliph Abd al-Malik (), who kept him in command of the war with the Azariqa.With the key support of the powerful Umayyad governor of Iraq, al-Hajjaj ibn Yusuf, al-Muhallab decisively defeated the Kharijites in 698.Throughout the thirteen-year conflict with the Kharijites, al-Muhallab was consistently viewed as indispensable by the Basrans and their successive Zubayrid and Umayyad rulers.