 After taking the city of Kairouan and overthrowing the Aghlabids in 909, the Mahdi Ubayd Allah declared himself caliph, which represented a direct challenge to the Umayyad's own claim to the caliphate.The Fatimids gained overlordship over the Idrisids, then launched a conquest of the Maghreb.To counter the threat, the Umayyads crossed the straits to take over Ceuta in 931, and actively formed alliances with Berber confederacies such as the Zanata and the Awraba.