[note 1] When the Berber Revolt of Maysara al-Matghari broke out in Morocco in 740, the bulk of the Ifriqiyan army, under the commander Habib ibn Abi Ubayda al-Fihri was overseas, on campaign in Sicily.
The governor of Ifriqiya Ubayd Allah ibn al-Habhab immediately dispatched instructions to Habib break off the expedition and ship the army back to Africa.
To keep the Berber rebels in check until the Sicilian expedition army returned, Obeid Allah assembled a cavalry-heavy column composed largely of the aristocratic Arab elite of Kairouan, and placed it under the command of Khalid ibn Abi Habib.
[1] Khalid ibn Abi Habib encountered the Berber rebel army in the outskirts of Tangiers, and after a couple of skirmishes, forced them to pull back.
But before junction could be made, the Berber rebel army, under a new commander, Khalid ibn Hamid al-Zanati, fell upon the Arab column in October/November 740.