Local opposition to the authorities began to intensify in September 945, when Kharijite insurgents occupied Tunis, resulting in general pillaging. With the rise of the Zirid dynasty Tunis gained importance, but the Sunni population tolerated Shi'ite rule less and less, and carried out massacres against the Shi'ite community. In 1048 the Zirid ruler Al-Muizz ibn Badis rejected his city's obedience to the Fatimids and re-established Sunni rites throughout all of Ifriqiya. This decision infuriated the Shi'ite caliph Al-Mustansir Billah. To punish the Zirids, he unleashed the Banu Hilal Arab tribe on Ifriqiya; a large part of the country was set to the torch, the Zirid capital Kairouan was razed in 1057, and only a few coastal towns, including Tunis and Mahdia, escaped destruction. Exposed to violence from the hostile tribes that settled around the city, the population of Tunis repudiated the authority of the Zirids and swore allegiance to the Hammadid prince El Nacer ibn Alennas, who was based in Béjaïa, in 1059. The governor appointed by Béjaïa, having reestablished order in the country, did not hesitate to free himself from the Hammadids to found the Khurasanid dynasty with Tunis as its capital. This small independent kingdom picked up the threads of trade and commerce with other nations and brought the region back to peace and prosperity.