In 1219 al-Mansur called together the leading men of Hama and made them swear allegiance to his eldest son, al-Muzaffar Mahmud, as his heir apparent, before sending al-Muzaffar to Egypt to aid Sultan al-Kamil. Some time later he sent his second son, an-Nasir Kilij Arslan to joinal-Mu'azzam in his campaigns in Palestine. However, as he lay dying, some of the leading emirs decided to invite an-Nasir back to Hama to usurp the throne in place of his brother, in the hope that they would be able to exercise real control under his nominal rule. Al-Mansur died in January 1221, and an-Nasir duly installed himself as ruler in Hama. He was on campaign with al-Mu'azzam, emir of Damascus at the time of his father’s death, and al-Mu’azzam would only agree to release him to return to Hama if he promised to pay 40,000 dirhams once he had control of the city. In Egypt, when al-Muzaffar learned of his father’s death, he obtained Sultan al-Kamil’s permission to go and claim his throne. On reaching Syria however he found his brother firmly established on the throne. None of the notables of Hama would support him in removing an-Nasir, and none of the other Ayyubid princes in Syria was interested in helping him, so he had to return to Egypt, where he was given an estate by al-Kamil. The two contenders for the throne of Hama were now aligned with the two major players whose rivalry divided the Ayyubid political world—al-Mu'azzam of Damascus and al-Kamil of Egypt. The rightful heir of Hama, al-Muzaffar, had the backing of al-Kamil, and Kilij Arslan looked to al-Mu’azzam for protection. Kilij Arslan managed to upset his backer however when he made overtures to a third leading Ayyubid emir, al-Ashraf, and failed to pay the 40,000 dirhams he had promised to al-Mu’azzam. Al-Mu’azzam therefore set out on a campaign to take Hama. Kilij Arslan was out hunting, but managed to hurry back into the city and hold it against the attackers. Rather than embark on a long siege, al-Muazzam took the towns of Salamiyah and Maarrat al-Nu'man for himself. In January 1223 he renewed his attack on Hama. However the prospect of the emir of Damascus taking Hama and becoming dominant throughout Syria prompted both al-Ashraf and al-Kamil to unite in demanding that al-Mu’azzam withdraw and leave Hama untouched. In the negotiations which followed, al-Mu’azzam had to return all of the territory he had taken and Kilij Arslan was left in control of Hama. He was however obliged to turn the city of Salamiyah over to his brother al-Muzaffar.
Deposition
Five years later, in November 1228, another set of negotiations took place at Tell al-Ajjul near Gaza between al-Kamil and al-Ashraf as they sought to agree a balance of power between them across the Ayyubid realms. The result was a comprehensive agreement on the redistribution of domains. Al-Kamil’s client al-Muzaffar was to be restored to Hama, together with Baarin and Maarrat an-Nu'man. Salamiyah was to be detached from the Hama domain and given to al-Mujahid of Homs. Al-Ashraf and a-Kamil now worked in tandem to put this plan into effect, and al-Kamil led his armies to Damascus in support of al-Ashraf who was laying siege to it. The city surrendered in June and almost at once, al-Kamil turned his attention to Hama. On 25 July 1229 al-Kamil, in alliance with al-Mujahid of Homs, laid siege to Hama to remove Kilij Arslan and restore al-Muzaffar. After a few days of siege Kilij Arslan came out to negotiate, and eventually agreed to leave Hama in return for receiving the fortress of Baarin.