# Hammadid–Zirid War

The Hammadid–Zirid War was the first in a series of conflicts between Hammadid and Zirid forces. It lasted from Hammad's removal of allegiance to the Fatimid Caliph and his submission to the Abbasids in 1014 until the recognition of Hammadid independence with the treaty between the two dynasties in early 1018. The war was primarily driven by Zirid Emir Badis's attempts to assert his authority over Hammad's domains, while Hammad sought to keep Zirid rule and authority out of Central Maghreb.
Hammad, a long-serving lieutenant of the Zirid emirs, had successfully divided the Zenata tribes and prevented them from establishing a foothold in Central Maghreb. For his victorious campaigns in the west, Hammad was granted overlordship over the city of Achir as well as the Central Maghreb and was permitted to build a fortified city that would serve as his base of operations. However, this greatly elevated his status, igniting feelings of envy and jealousy among his enemies, who began to slander him and incite Badis against him.

## Background

The final break between Hammad and his nephew Badis occurred around 405/1014. When Badis' son al-Mansur was declared heir to the Zirid throne, Badis attempted to carve a small principality out of Hammad's territory for the new crown prince. He demanded that Hammad relinquish control of the districts of Constantine, Tījis, as well as Qasr al Ifriqi. Hammad refused, and soon after, he removed the name of the Fatimid caliph from the khutba, replacing it with that of the Sunni Abbasid caliph in Baghdad. He then proceeded to massacre the Shi'a in his domains. By changing the state creed so abruptly and violently, Hammad was proclaiming his complete independence from the Zirid court. Badis could not let such a challenge go unpunished and personally led an expedition to chastise his uncle.
Badis consulted Ibrahim ibn Buluggin, who on the same occasion was the brother of Hammad, on who should deliver the letter to Hammad. Ibrahim eagerly volunteered, saying, 'Our master will not find a servant among his servants more committed to his service than me.' He pledged that his journey would not take more than twenty days. Badis, on the advice of someone close to him, was advised to detain Ibrahim, preventing him from traveling until Hammad's obedience and promptness to his orders could be confirmed. But ultimately, he said to Ibrahim, 'Go to your brother Hammad. If you are truthful in what you said and fulfill your promises, then proceed. Otherwise, do what you intend.' Ibrahim left with Hashim bin Jaafar on 11 April 1015 AD, accompanied by 400,000 dinars in gold and all his treasures, men, and slaves. Badis did not obstruct him, otherwise, his departure with all his wealth and men would have indicated otherwise. Hashim ibn Jaafar sensed that Ibrahim might betray him when they got closer to his brother. Shortly after, Ibrahim excused himself to attend to an urgent matter in Béja, promising to catch up quickly.
As soon as Ibrahim reached Tamdit, which is a two-day journey from Laribus, he wrote to Hammad to inform him of his plans. Hammad arrived with an entourage of thirty thousand horsemen. They united their forces and renounced their allegiance. When Hammad reached Béja on his way to meet Badis, the people of the city sought his protection, and he assured them of their safety. However, once he entered the city, he started killing, looting, and taking their wealth. This served as a lesson for all cities and created a significant obstacle for Hammad due to his own policies. In contrast, Badis remained faithful to those who trusted and allied with him. As a result, many of Hammad's supporters, including Zenata and Sanhadja tribes, abandoned him. When Hammad reached Achir, his city where his subject Khalaf al-Himyari resided, Khalaf prevented him from entering and declared his allegiance to Badis, further demonstrating the impact of their differing policies. This left Hammad in a difficult position as he hoped to fortify himself in the city.

## Aftermath

All these circumstances set the stage for the outcome of the battle between Badis and Hammad. When Badis crossed the Chelif River after seizing the city of Achir at the beginning of Jumada al-Awwal 406 AH (1015 AD) and confronted Hammad, Badis's men were determined to either endure or die, knowing Hammad's cruelty towards captives. Hammad was utterly defeated, and his army was plundered. If Badis's troops had not been preoccupied with looting, Hammad himself would not have escaped. The spoils and wealth taken were beyond measure. Hammad then proceeded to fortify himself at the fortress of Timici before joining his brother five days after at Qal'at Bani Hammad. Upon reaching their fort, Ibrahim informed his brother of the lack of supplies in case of a long siege by Badis. They then proceeded to sack the city of Dkama not far from M'sila. The city had already submitted to Badis, which angered Hammad. He ultimately killed three hundred men, took all their supplies, and returned to his fortress.
Meanwhile, Badis continued eastward and arrived in M'Sila on 13 November 1015 AD. He received an envoy from his uncle Ibrahim, delivering apologies and reminding Badis of Hammad's past services. Badis likely set conditions deemed unfair, such as unconditional surrender. He left his army encircling the fortress and distributed money among his soldiers to incite enemy desertions. This strategy caused part of Hammad's army to desert and led to a shortage of supplies and rising prices within the besieged fortress. It seemed that Hammad was on the verge of defeat, and his dynasty appeared to be on the brink of extinction. Unfortunately for the Zirids, Badis died unexpectedly in 407 AH/1016, and he was succeeded by his eight-year-old son al-Mu'izz since al-Manşūr had passed away before his father. The Zirid army withdrew to Qayrawan, allowing Hammad to reclaim his lost territories. The following year, Hammad sent his son al-Qa'id to the Zirid court with gifts, and a treaty was signed maintaining the status quo. The Zirids were now willing to acknowledge an independent Hammadid state in the Central Maghrib, their ancestral homeland.

## Hammadid–Zirid treaty

Nearly a year had elapsed since Hammad's conflict with Kurama, al-Muizz's uncle, in Achir. Taking advantage of every fleeting opportunity, Hammad managed to defeat Kurama, partly due to the plundering of Kurama's treasury by his own men. Despite Kurama's advantage of seven thousand men compared to Hammad's fifteen hundred, and the fact that all the people of Achir were against him, Hammad was victorious. During this period, al-Muizz mobilized to confront Hammad on July 31, 1017. At that time, Hammad was besieging Bagai after capturing M'sila and Achir. Al-Muizz's advance forced Hammad to withdraw from Bagai. They engaged in battle at the end of Rabi' al-Awwal, which corresponds to the 26th of August 1017. Within a few hours, Hammad and his forces were decisively defeated. Al-Muizz's troops overwhelmed them, capturing their equipment, wealth, and other possessions. Ibrahim, Hammad's brother, was taken prisoner, while Hammad, though injured, managed to escape, and his followers scattered.
Back at his fortress, Hammad sent an envoy to al-Muizz seeking forgiveness and proposing reconciliation. Al-Muizz responded, "If you are sincere, send your son al-Qa'id to us." Hammad replied that he would send al-Qa'id or come himself if he received a letter from his brother Ibrahim confirming al-Muizz's assurances. Ibrahim arrived, secured the promises from al-Muizz, and informed Hammad, expressing gratitude for al-Muizz's kindness. Historian Abdelhalim Oweis notes that several factors likely influenced al-Muizz's acceptance of Hammad's offer. The young age of the Emir, who had not yet turned nine, and concerns among the Emir and his advisors about facing a potentially greater threat than Hammad likely played roles.
Despite these factors, al-Muizz reached an agreement with Hammad's son, al-Qa'id. Under the terms, Hammad was granted control over M’sila, Tobna, Zab, Achir, Tahert, and any newly conquered lands in the Maghreb. Al-Muizz also appointed al-Qa'id to oversee Tobna, Mars al-Dejaj, the lands of the Zouaoua, Magra, Dekma, Belezma, and Souk Hamza. The agreement was not simply about dividing the Central Maghreb between the father and his son. Instead, it acknowledged Hammad as an independent ruler over M’sila, Tobna, the Zab, Achir, and Tahert, as well as any additional regions he might conquer in the Central Maghreb. It was anticipated that al-Qa'id would succeed his father. Thus, the Hammadid–Zirid agreement established Hammad as an independent emir in the Central Maghreb, leading to a division of the Sanhadja tribe into two states: the Zirid state in Ifriqiya and the Hammadid state in the Central Maghreb.