The Battle of al-Mada'in was fought near al-Mada'in in central Iraq between the armies of the Hamdanids and the Baridis, for control over Baghdad, the capital and seat of the Abbasid Caliphate, that was around 22 kilometres (14 mi) away and then under control of the Hamdanids. In a fiercely contested battle over four days (16–19 August 942) that cost both sides many casualties, the Hamdanid army prevailed. They were too exhausted to pursue, however, which allowed the Baridis to withdraw to Wasit and then Basra.
 By the 930s, after a series of civil wars that enfeebled its central government, the Abbasid Caliphate had splintered and shrunk to its core territories. Effective control over the more distant provinces of the empire had long been lost, but now autonomous local dynasties emerged in the territories around the Abbasids' metropolitan region of Iraq itself: Egypt and Syria came under the rule of the Ikhshidids, the Hamdanids secured control over Upper Mesopotamia, while most of Iran was ruled by Daylamite warlords, among whom the Buyids became prominent. Even in Iraq itself, the authority of the caliphal government was challenged: in the south, around Basra, the Baridi family under Abu Abdallah al-Baridi established its own domain, more often than not withholding the tax revenues from Baghdad to fill their own coffers. These autonomous rulers vied with one another, and with military warlords from what remained of the Abbasid army, over control of Baghdad, the administrative centre of Iraq and seat of the Abbasid caliphs. From 936 on, the caliphs were sidelined by a series of military dictators who enjoyed the title of amir al-umara. A convoluted struggle for control of the office of amir al-umara, and the figurehead caliphate with it, broke out among the various local rulers and the Turkish military chiefs, which would end in 946 with the victory of the Buyids.
 In this turmoil, the Baridis managed to advance their positions from Basra to Wasit, gain the support of the Daylamites in the Abbasid army, and briefly capture Baghdad for the first time in June 941. Although chased out of the capital by an uprising of the troops and the populace, in March 942 the Baridis managed to defeat the forces of the amir al-umara Ibn Ra'iq and enter the capital once more. Ibn Ra'iq and Caliph al-Muttaqi fled north to Mosul, ruled by the Hamdanids. The Hamdanid leader, Hasan, had Ibn Ra'iq murdered and was named by the Caliph amir al-umara in his stead, with the laqab (honorific epithet) of Nasir al-Dawla ("Defender of the Dynasty"). Baridi rule in Baghdad was tyrannical and chaotic, as the new rulers of the capital aimed only at extracting money; the city was rife with famine, disease, and lawlessness. Many of the Turkish officers in Ibn Ra'iq's employ who had previously defected to the Baridis, such as Tuzun, plotted against the Baridi governor, Abu Abdallah's younger brother Abu'l-Husayn al-Baridi. When this was betrayed, they fled north for Mosul with many of their troops, where they encouraged the Caliph and the Hamdanids to campaign against Baghdad.
 As the Hamdanids moved on Baghdad, Abu'l-Husayn abandoned the city and fled to Abu Abdallah in Wasit. The Hamdanids entered the city to a triumphal reception in mid-July. The situation was still in the balance, however, as Abu Abdallah gathered his forces at Wasit and began moving against the capital. Unease spread in Baghdad at the news, and the Caliph sent his harem upstream to Samarra for safety. Command of the Hamdanid army was entrusted to Nasir al-Dawla's brother Ali, with the Turks under their own commanders Tuzun and Khajkhaj, while the Baridi army was led by Abu'l-Husayn.
 The two armies met at the village of Gil, two parasangs—c. 12 kilometres (7.5 miles)—south of al-Mada'in. Al-Mada'in was in turn around 22 kilometres (14 mi) south of Baghdad. The battle was fought over four days, 16–19 August. At first, the Baridis had the upper hand, and the Hamdanids were routed. Nasir al-Dawla managed to rally them at al-Mada'in, and defeat the Baridis. Several high-ranking Baridi officials and commanders, including their army secretary, were captured; others defected to the Hamdanids, as did the entire Daylamite contingent in the Baridi army. On the other hand, so depleted and exhausted were the Hamdanids that they were unable to pursue the Baridis. Only a week later did they move on Wasit, where they found the Baridis gone for their stronghold of Basra. 
 On 2 September, Nasir al-Dawla staged a triumphal entry into Baghdad with the captive Baridi commanders, and al-Muttaqi awarded the laqab of Sayf al-Dawla ("Sword of the Dynasty") to Ali, by which he was to become famous later as the emir of Aleppo and the champion of Islam against the Byzantines. This double award to the Hamdanid brothers marked the first time that a laqab incorporating the prestigious element al-Dawla was granted to anyone other than the vizier, the Caliphate's chief minister.
 The costly victory at al-Mada'in was soon undone: while Sayf al-Dawla wanted to continue the campaign against the Baridis, his brother—"whether from jealousy or negligence", according to historian Harold Bowen—did not send him the funds requested. Furthermore, the two Turkish generals, Tuzun and Khajkhaj, began showing signs of insubordination. The growing unreliability of his army forced Sayf al-Dawla to abandon the campaign and secretly flee to Baghdad. Nasir al-Dawla, dismayed at these developments and exposed far from his real power-base, decided to give up the capital, and in June 943, the two brothers returned to Mosul. After Sayf al-Dawla left, Tuzun and Khajkhaj agreed to divide the spoils: Tuzun would become amir al-umara, with Khajkhaj as commander-in-chief; but soon Tuzun had his colleague blinded and sidelined. 
 After becoming the master of Baghdad, Tuzun pursued a peace with the Baridis of Basra, sealed with a marriage alliance. The alliance between Tuzun and the Baridis was seen as a threat by Caliph al-Muttaqi and his advisors. In September 943, while Tuzun was still in Wasit, the caliph once more appealed to the Hamdanids for aid: an army under Nasir al-Dawla's cousin al-Husayn appeared before Baghdad, and the caliph left the capital and went north, meeting Nasir al-Dawla at Tikrit. Tuzun immediately abandoned Wasit and pursued the caliph north, heavily defeated Sayf al-Dawla in two battles near Tikrit, and captured Mosul itself. An agreement was concluded between Tuzun and the Hamdanids on 26 May 944, whereby Nasir al-Dawla renounced his claims on the Caliphate's core lands in central Iraq, receiving in return recognition for his control over Upper Mesopotamia and his claims over Syria, in exchange for an annual tribute of 3.6 million dirhams. 
 Tuzun's victory was concluded when al-Muttaqi was persuaded to return to the capital, only to be deposed and blinded, and al-Mustakfi placed in his stead. Tuzun's ascendancy did not last long, as almost immediately he had to face the attacks of the Buyids. When Tuzun himself died in 945, his secretary Muhammad ibn Shirzad tried to secure Hamdanid support, but to no avail. On 16 January 946, the Buyids captured Baghdad and inaugurated a century of Buyid rule over Baghdad. The Baridis also faced mounting challenges at the same time: they had to defend Basra against the ruler of Oman, and, their resources exhausted in the long contests for Baghdad, they now turned on one another. The youngest Baridi brother, Abu Yusuf, was assassinated by the eldest, Abu Abdallah, who in turn died in June 944. His son Abu'l-Qasim remained as ruler of Basra until the Buyids, following their capture of Baghdad, expelled him in 947.