In 697, the Byzantine emperor Leontios () dispatched a strong fleet, which retook Carthage, which resulted in the city's Arab forces fleeing to Kairouan, which had been established by the Arabs in 670 as their capital in Ifriqiya. In 698, Hassan forces recaptured Carthage, which was destroyed, its walls torn down, its water supply cut off, and its harbors made unusable. Afterwards, Hassan moved against the Berbers led by their warrior queen, al-Kahina. Though information about her is difficult to disentangle from legend, it is apparent that she ruled the Aures, a rugged massif a few days' distance from Arab possessions in Ifriqiya and strategically located between Ifriqiya and the western half of North Africa (the Maghreb, i.e. modern-day Algeria and Morocco). According to the 13th-century historian Ibn Idhari, who provides the fullest known account of al-Kahina, Hassan, upon entering Kairouan, inquired about the strongest king left in Ifriqiya and was informed that al-Kahina commanded the loyalty of the Berber tribes and if she should be eliminated, the Maghreb would fall to Hassan. Skipping over the Byzantine fortress of Baghaya (al-Majjana), which al-Kahina had preemptively captured and destroyed to prevent its utilization by the Arabs, Hassan met the Berbers at the Battle of Meskiana. There, he was dealt a heavy blow by al-Kahina, forcing him to retreat first to the vicinity of Gabes before evacuating Ifriqiya altogether. Many of his troops were killed or captured by the Berbers as they fled. He stopped at an area containing several forts, later collectively called "Qusur Hassan" after him, about four-days march to the east of Tripoli.