Hafsid dynasty

The Hafsids (الحفصيون al-Ḥafṣiyūn) were a Sunni Muslim dynasty of Berber descent who ruled Ifriqiya (modern day Tunisia, western Libya, and eastern Algeria) from 1229 to 1574.

Almohad Ifriqiya
The Hafsids were of Berber descent, although to further legitimize their rule, they claimed Arab ancestry from the second Rashidun caliph Omar. The ancestor of the dynasty (from whom their name is derived), was Abu Hafs Umar ibn Yahya al-Hintati, a Berber from the Hintata tribal confederation, which belonged to the greater Masmuda confederation in present-day Morocco. He was a member of the Council of Ten, one of the highest Almohad political bodies, and a close companion of Ibn Tumart, the Almohad movement's founder.

The son of Abu Hafs, Abu Muhammad Abd al-Wahid ibn Abi Hafs, was appointed by the Almohad caliph Muhammad al-Nasir as governor of Ifriqiya (generally present-day Tunisia, eastern Algeria, and western Libya) where he ruled from 1207 to 1221. He was established in Tunis, which the Almohads had chosen as the province's administrative capital. His appointment came in the wake of the defeat of Yahya Ibn Ghaniya, who had launched a serious attack against Almohad authority in the region. Abu Muhammad Abd al-Wahid was ultimately quite effective in keeping order. The caliph had granted him a significant degree of autonomy in governing, partly to help persuade him to accept this difficult position in the first place. This laid the groundwork for a future Hafsid state.

When Abu Muhammad Abd al-Wahid died in 1221, the Almohad chiefs in Ifriqiya initially elected his son, Abu Zayd Abd al-Rahman, as the next governor. However, the Almohad caliph in Marrakesh, Yusuf II al-Mustansir, had not consented to this and was able to overrule this and appoint his own relative to the position. As Almohad authority weakened over the following years, local opposition to the Almohad governor compelled the Almohad caliph Abdallah al-Adil to appoint another Hafsid family member to the post in 1226. He chose Abu Muhammad Abdallah, a grandson of Abu Hafs. Abu Muhammad Abdallah's brother, Abu Zakariya Yahya, arrived in Tunis before him and began to reestablish order. When al-Ma'mun, the brother of Abdallah al-Adil, rebelled against the latter's authority from al-Andalus, Abu Zakariya sided with him, whereas Abu Muhammad Abdallah remained loyal to the caliph in Marrakesh. Al-Ma'mun's eventual victory resulted in Abu Zakariya being placed in charge of Ifriqiya in 1228.

Rise to power
A year later, in 1229, al-Ma'mun officially renounced Almohad doctrine. Abu Zakariya used this as a pretext to repudiate his authority and to declare himself independent. By this point, Al-Ma'mun did not have the means to stop him or to reassert control over Ifriqiya. Initially, Abu Zakariya had his name mentioned in the khutba (the sermon during Friday prayer) with the title of amir, but in 1236 or 1237 he began to adopt the caliphal title of Amir al-Mu'minin, in direct challenge to the Almohad caliph in Marrakesh.

Abu Zakariya annexed Constantine (Qusantina) and Béjaïa (Bijaya) in 1230. In 1234, he chased Yahya Ibn Ghaniya out of the countryside south of Constantine in 1234, ending this lingering threat. In 1235 he captured Algiers and then established his authority as far as the Chelif River to the west. In the following years he subdued various rural tribes, such as the Hawwara, but allowed some of the Banu Tujin tribes in the central Maghreb to govern themselves as small vassal states that secured his eastern borders. He welcomed many refugees and immigrants from al-Andalus who were fleeing the advance of the Reconquista. He appointed some of them to important political positions and recruited Andalusi military regiments as a way of counteracting the power and influence of traditional Almohad elites.

For a time, the Nasrid ruler of Granada in al-Andalus, Ibn al-Ahmar, briefly acknowledged Abu Zakariya's suzerainty in an attempt to enlist his help against Christian forces. Ultimately, Hafsid intervention on the Iberian Peninsula was limited to sending a fleet to Muslim Valencia's aid in 1238. Abu Zakariya showed more interest in trying to recreate some of the former authority of the Almohads over the Maghreb and he made attempts to extend his control further west. In 1242, he captured Tlemcen from the Zayyanids, but the Zayyanid leader Yaghmurasan evaded him. The two leaders eventually came to an agreement, with Yaghmurasan continuing to rule in Tlemcen but agreeing to formally recognize Abu Zakariya's authority. That same year, Sijilmasa and Ceuta (Sabta) also recognized his authority, though these would later fall under Marinid control. This policy of western expansion ended with Abu Zakariya's death (1249).

Consolidation and division
His successor, Muhammad I al-Mustansir (r. 1249–1277), focused on consolidating the Hafsid state in Ifriqiya. The state benefited from expanding trade with both Europe and the Sudan region (south of the Sahara). In the western Maghreb (present-day Morocco), the Marinids, who had not yet fully established their rule in the region, formally recognized his authority in 1258. With the fall of Baghdad, the home of the Abbasid caliphs, that same year, the Hafsids were briefly seen as the most important rulers of the Muslim world. The Sharif of Mecca, Abu Numayy, temporarily recognized him as caliph in 1259.

It was during his reign that the failed Eighth Crusade took place, led by Louis IX of France. After landing at Carthage, Louis died of dysentery in the middle of his army decimated by disease in 1270.

After al-Mustansir's death in 1277, the Hafsids were riven by internal conflict, aggravated by interference from Aragon. This resulted in a split in the dynasty: one branch ruled from Tunis in the east and another branch ruled from Béjaïa (Bijaya) and Constantine (Qusantina) in the west. This division continued to characterize Hafsid politics for much of its history, with the balance of power sometimes shifting from one side to another and with intermittent successes at unifying both branches under one rule. After the initial split, the first successful reunification took place under Abu Yahya Abu Bakr II ((r. 1318 – 1346)), the ruler of the western branch who managed to take control of Tunis.

Marinid invasions and internal crisis
Abu Yahya Abu Bakr's rule remained unstable and he resorted to making alliances with the Zayyanids and Marinids to the west. His agreement with the Marinid ruler, Abu al-Hasan ((r. 1331 – 1348)), included a marriage to his sister, who subsequently died during a failed Marinid expedition in Spain, followed by another marriage to his daughter. When Abu Yahya Abu Bakr died in 1346, his intended heir, Abu'l Abbas, was killed in Tunis by his brother, Umar, who seized power. Abu'l Abbas's chamberlain, Abu Muhammad Abdallah ibn Tafrajin, sent a letter to Abu al-Hasan urging him to intervene and invade Ifriqiya. Abu al-Hasan, having already conquered Tlemcen in 1337, seized the opportunity to further expand. He conquered Tunis in 1347 and the Hafsid governors in the region accepted his authority.

The invasion, however, disturbed the balance of power in favour of the Bedouin Arab tribes, whom the Marinids were unable to sway. Ibn Tafrajin, who had hoped to be placed in power by the Marinids, fled to Egypt. The situation in Ifriqiya devolved into further disorder and internal rivalries, and Abu al-Hasan was forced to return west in 1349, partly to deal with a coup d'état by his son, Abu Inan. Ibn Tafrajin returned to Ifriqiya and, with Bedouin support, installed another young son of Abu Yahya Abu Bakr, Abu Ishaq, as ruler. Abu Inan, having successfully taken the throne from his father, invaded Ifriqiya again and captured Tunis in August 1357, but he was soon forced by his own troops to abandon the region. He returned west, retaining control only of Constantine and the cities of the central Maghreb for a time.

During the mid-14th century, plague epidemics brought to Ifriqiya from Sicily caused a considerable fall in population, further weakening the Hafsid realm. To stop raids from southern tribes during plague epidemics, the Hafsids turned to the Banu Hilal to protect their rural population.

Apogee
After the Marinid threat ended, attempts to reunify the Hafsids failed until Abu al-Abbas Ahmad II ((r. 1370 – 1394)), the emir of Béjaïa and Constantine, conquered Tunis in 1370. A capable ruler and military leader, he reestablished Hafsid authority on stronger terms, centralizing power to a greater extent than ever before. Meanwhile, the Zayyanids and Marinids were occupied by internal matters.

Abu Faris Abd al-Aziz II's reign ((r. 1394 – 1434)) was considered the apogee of Hafsid power and prosperity by contemporary writers. He further consolidated his dynasty's power in Ifriqiya and extended his influence over the Zayyanids and Marinids (and the Wattasids who succeeded the latter).

The beginning of his reign was not easy since the cities of the south revolted against him. However, the new sultan quickly regained control: he reoccupied Tozeur (1404), Gafsa (1401), and Biskra (1402), subdued tribal power in the regions of Constantine and Béjaïa (1397–1402), and appointed governors of these regions to be elected officers. He also intervened against his western and eastern neighbors. He annexed Tripoli (1401) and Algiers (1410–1411). In 1424, he defeated the Zayyanid sultan, Abu Malik Abd al-Wahid, and placed another Zayyanid, Abu Abdallah Muhammad IV, on the throne of Tlemcen as his vassal. In 1428, the latter became embroiled in another war with Abu Malik Abd al-Wahid – who had now won his own support from the Hafsids – and was eventually replaced by yet another Zayyanid relative with Abu Faris Abd al-Aziz's help in 1431. Around the same time (probably in 1426), Abu Faris Abd al-Aziz also helped to install Abd al-Haqq II on the Marinid throne in Fez – under the regency of Abu Zakariya Yahya al-Wattasi – and thus obtained from him a recognition of Hafsid suzerainty.

In 1429, the Hafsids attacked the island of Malta and took 3000 slaves, although they did not conquer the island. Kaid Ridavan was the military leader during the attack. The profits were used for a great building programme and to support art and culture. However, piracy also provoked retaliation from the Christians, which several times launched attacks and crusades against Hafsid coastal cities such as the Barbary crusade (1390), the Bona crusade (1399) and the capture of Djerba in 1423.

Abu Faris Abd al-Aziz II died in 1434 during another expedition against Tlemcen. His successor, Abu 'Amr 'Uthman, had the longest reign of any Hafsid ((r. 1435 – 1488)). He largely continued the strong rule of his predecessors but he had to contend with greater challenges, including internal politics, restive Bedouin tribes in the south, and the Wattasids in the west.

Uthman conquered Tripolitania in 1458 and appointed a governor in Ouargla in 1463. He led two expeditions to Tlemcen in 1462 and 1466 and made the Zayyanids his vassals, while the Wattasid state in Morocco also formally accepted his authority. The entire Maghreb was thus briefly under Hafsid suzerainty.

Fall
In the 16th century the Hafsids became increasingly caught up in the power struggle between Spain and the Ottoman Empire-supported Corsairs. The Ottomans conquered Tunis in 1534 and held it for one year, driving out the Hafsid ruler Moulay Hassan. A year later the King of Spain and Holy Roman Emperor Charles V seized Tunis, drove the Ottomans out and restored Muley Hassan as a Habsburg tributary. Due to the Ottoman threat, the Hafsids were vassals of Spain after 1535. The Ottomans again conquered Tunis in 1569 and held it for four years. Don Juan of Austria recaptured it in 1573. The Ottomans reconquered Tunis in 1574, and Muhammad VI, the last Caliph of the Hafsids, was brought to Constantinople and was subsequently executed due to his collaboration with Spain and the desire of the Ottoman Sultan to take the title of Caliph as he now controlled Mecca and Medina.

Economy
The Hafsids, with their location in Ifriqiya, was rich in agriculture and trade. Instead of placing the capital at inland cities such as Kairouan, Tunis was chosen as the capital due to its position on the coast as a port linking the Western and Eastern Mediterranean. Christian merchants from Europe were given their own enclaves in various cities on the Mediterranean coast, promoting trans-Mediterranean trade. Under the Hafsids, commerce and diplomatic relations with Christian Europe grew significantly, however piracy against Christian shipping grew as well, particularly during the rule of Abd al-Aziz II (1394–1434). By the mid-14th century, the population of Tunis had grown to 100,000. The Hafsids also had a large stake in trans-Saharan trade through the caravan routes from Tunis to Timbuktu and from Tripoli to sub-Saharan Africa.

Intellectual activity
The Hafsids were effective patrons of culture and education. They were the first to introduce madrasas to the Maghreb. Arabic literacy and religious education thus increased, with Kairouan, Tunis and Bijaya hosting famous university-mosques. Kairouan continued to serve as a center of the Maliki school of religious doctrine. As the political center of the country shifted to Tunis, the Great Mosque of al-Zaytuna, the city's main mosque, became the country's leading center of learning. Of great impact on culture were immigrants from al-Andalus, whom Abu Zakariya encouraged to come to his realm in the 13th century. Among the most important figures was the famous historian and intellectual, Ibn Khaldun.

Architecture
The Hafsids were significant builders, particularly under the reigns of successful leaders like Abu Zakariya (r. 1229–1249) and Abu Faris (r. 1394–1434), though not many of their monuments have survived intact to the present-day. While Kairouan remained an important religious center, Tunis was the capital and progressively replaced it as the main city of the region and the main center of architectural patronage. Unlike the architecture further west, Hafsid architecture was built primarily in stone (rather than brick or mudbrick) and appears to have featured much less decoration. In reviewing the history of architecture in the western Islamic world, scholar Jonathan Bloom remarks that Hafsid architecture seems to have "largely charted a course independent of the developments elsewhere in the Maghrib."

The Kasbah Mosque of Tunis was one of the first works of this period, built by Abu Zakariya (the first independent Hafsid ruler) at the beginning of his reign. Its floor plan had noticeable differences from previous Almohad-period mosques but the minaret, completed in 1233, bears very strong resemblance to the minaret of the earlier Almohad Kasbah Mosque in Marrakesh. Other foundations from the Hafsid period in Tunis include the Haliq Mosque (13th century) and the al-Hawa Mosque (1375). The Bardo Palace (today a national museum) was also begun by the Hafsids in the 15th century, and is mentioned in historical records for the first time during the reign of Abu Faris. The Hafsids also made significant renovations to the much older Great Mosque of Kairouan – renovating its ceiling, reinforcing its walls, and building or rebuilding two of its entrance gates in 1293 – as well as to the Great Mosque of al-Zaytuna in Tunis.

The Hafsids also introduced the first madrasas to the region, beginning with the Madrasa al-Shamma῾iyya built in Tunis in 1238 (or in 1249 according to some sources  ). This was followed by many others (almost all of them in Tunis) such as the Madrasa al-Hawa founded in the 1250s, the Madrasa al-Ma'ridiya (1282), and the Madrasa al-Unqiya (1341). Many of these early madrasas, however, have been poorly preserved or have been considerably modified in the centuries since their foundation. The Madrasa al-Muntasiriya, completed in 1437, is among the best preserved madrasas of the Hafsid period.