Hafsid dynasty

The Hafsid dynasty was a Sunni Muslim Berber dynasty that  ruled over Libya, Tunisia, and eastern Algeria from 1229 to 1574, with Tunis serving as its capital. The Hafsids were brought into power by the Almohad Caliphate, which appointed the Banu Hafs Berber tribe as the governors of North Africa at the time of the Reconquista in the Iberian Peninsula. In 1229, the Hafsids declared independence from the Almohads, and the dynasty resisted King Louis IX of France's failed Eighth Crusade to Tunis in 1270. During the 14th century, the dynasty temporarily declined as the Marinid dynasty conquered it twice, but the Hafsids returned to power during the early 15th century and began to open commerce with the Christian kingdoms of Europe (despite committing acts of piracy against them). In 1534, the Ottoman Empire conquered the Hafsid capital of Tunis, and the Hafsids became vassals of Spain a year later when the Spanish reconquered Tunis. In 1574, the Ottomans reconquered Tunis and had the last Hafsid ruler, Muhammad IV, executed in Constantinople.