After the defeat of Caliph al-Amin's army at the Battle of Rayy and the death of his commander Ali ibn Isa ibn Mahan, the armies of al-Amin were in retreat moving west from Iran to Iraq back to their base camp at Baghdad. Al-Ma'mun's general Tahir ibn Husayn, the victor of Battle of Rayy decided to chase the retreating army. However, reinforcements from Baghdad arrived under the able leadership of Abd al-Rahman ibn Jabala. Abd al-Rahman decided to fortify himself behind the walls and gates of Hamadan. But when Tahir ibn Husayn came closer to the city, Abd al-Rahman decided to come out and meet this threat head on. Twice Abd al-Rahman was driven back into the city. Tahir ibn Husayn began a blockade of the city and Abd al-Rahman’s forces began to shower arrows and throw stones from the city walls. Eventually Abd al-Rahman was obliged to leave and ask for terms due to resentment of the people of Hamadan at the occupation and rapidly depleting supplies. Tahir ibn Husayn, realizing that Abd al-Rahman ibn Jabala had left the city, decided not to waste further time in Hamadan and marched westward towards Baghdad. On his way, he reached a certain pass named Asadabad where his army was ambushed by Abd al-Rahman ibn Jabala. The surprise attack caught Tahir’s troops off guard. But because the army was well disciplined the infantry managed to hold them off until Tahir ibn Husayn’s cavalry was ready to attack. In the ensuing confusion Abd al-Rahman ibn Jabala who had dismounted his horse was killed and his army defeated. After the short delay, Tahir ibn Husayn began his march towards Baghdad again. The news of the defeat of first Ali ibn Isa ibn Mahan and now Abd al-Rahman ibn Jabala reached Caliph al-Amin and greatly distressed him. It seemed to the people of Baghdad that Tahir ibn Husayn was unstoppable. Nevertheless, people in al-Ahwaz under the leadership of Muhammad ibn Yazid al-Muhallabi put up a fierce resistance to the armies of Tahir ibn Husayn. After defeating the army of al Muhallabi, Tahir reached the gates of Baghdad and at the right time too as his reinforcements arrived under the leadership of Harthama ibn A'yan.
The Siege
The siege has no parallel in warfare of the time. Although the city was surrounded by walls most of the population lived in suburbs which were not. The siege was therefore not an attack on a fortified perimeter but rather street fighting, house to house invasion as well as temporary improvised fortifications. It was extremely destructive especially for the civilian population. Immediately, Tahir ibn Husayn ordered the other commanders namely Zuhayr ibn al-Musayyab al-Dabbi and Harthama ibn A’yan to set up camps at Qasr Raqqat Kalwadha and Nahr Bin respectively, while he set up camp at al-Anbar Gate. They set up siege engines, mangonels, and dug trenches. Both sides are known to have used siege weapons. At one point, a general of al-Amin known as al-Samarqandi used boats to transport mangonels on the riverTigris and bombard enemy positions in the suburbs of Baghdad inflicting more damage to the civilian population than to the besiegers. There were several vicious battles, such as at al-Amin's palace of Qasr Halih, at Darb al-Hijarah and al-Shammasiyyah Gate. In the later stages of the siege irregulars came to the aid of al-Amin. As things were getting worse and Tahir ibn Husayn pushed into the city, al-Amin sought to negotiate safe passage out. Tahir ibn Husayn reluctantly agreed on the condition that al-Amin turn over his scepter, seal and other insignia of the caliphal office. Al-Amin, reluctant to do so, tried to leave on a boat. Tahir ibn Husayn noticed the boat and sent his men after the Caliph, who was captured and brought to a room where he was executed. His head was placed on the al-Anbar Gate. Muhammad ibn Jarir al-Tabari quotes Tahir's letter to the new Caliph al-Ma'mun informing him of al-Amin's capture and execution and the state of peace resulting in Baghdad.
Aftermath
The end result was that al-Ma'mun became the new Abbasid Caliph. Yet, he would not arrive in Baghdad until 819 due to the destruction and continued disturbances in the city.