The Hafsid Dynasty of Ifriqiya
Named after Muhammad bin Abu Hafs of the Masmuda tribe of Morocco, the Hafsid Dynasty ruled the area stretching from the west of Libya to the east of Algeria, known at the time as Ifriqiya. Muhammad bin Abu Hafs was appointed to the position of governor of Ifriqiya by the Caliph of the Almohad Empire at the time, Muhammad an-Nasir. The Hafsid dynasty ruled from 1229 to 1574, during which time they were constantly under threat of attack by the Banu Ghaniya –relatives of the Almoravids who had earlier been defeated and replaced by the Almohads.
The Hafsids acted as governors for the Almohads until declaring independence in 1229. They continued to rule the region with Abu Zakariya Yahya as their leader. He organized the administration of the newly independent Ifriqiya, establishing Tunis as the cultural and economic center of the Hafsid Empire. During this time, a large number of Muslims sought refuge from the conflict on the Iberian Peninsula where the Spanish were reconquering Castile and Aragon. These refugees were assimilated into the Hafsid dynasty. Abu Zakariya also conquered the settlement of Tlemcen, taking the Zayyanids (Abdalwadids) as his vassal in 1242.
Muhammad I al-Mustansir succeeded Abu Zakariya in 1249, taking the title of Caliph, and ruling until 1277. During the 1300s, the Hafsid Empire was twice conquered by the Merinids of Morocco, but managed to regain their empire which had been weakened by conquests and a fall of population due to epidemics. During the rule of Abd al-Aziz II from 1394 to 1434, the Hafsids traded commercially with Christian Europe, both legitimately and illegitimately, as piracy against Christian shipping proved lucrative. Retaliation by Christian Europe, particularly, Aragon and Venice, resulted in the coastal cities of the Hafsid Empire being attacked repeatedly.
With the development of a trade route through the Sahara, and commercial opportunities with Egypt, the cities of the empire became independent and the Hafsid dynasty began to wane. In the 16th century, the Hafsids got caught up in the ongoing power struggle between the Corsairs – privateers supported by the Ottoman Empire – and Spain. Seeking assistance in withstanding the Ottoman threat, the Hafsids became vassals of Spain after 1535. Tunis was conquered by the Ottomans in 1574 and the last Caliph of the Hafsid dynasty, Muhammad IV, was taken to Constantinople where he was executed for collaborating with Spain. A branch of the Hafsid family escaped the wrath of the Ottoman Empire by being taken to Tenerife by the Spanish, but the Hafsid dynasty that once ruled Ifriqiya, including part of modern-day Algeria, had come to an end.