He was killed in the course of the civil war between al-Amin and al-Ma'mun while defending al-Ahwaz against the army of Tahir ibn al-Husayn.
[2] When the war began, the fighting between the two sides did not initially take place near al-Ahwaz, but by the autumn of 811 al-Ma'mun's general Tahir had advanced from Khurasan to the district of Hulwan at the edge of northern Iraq.
Soon after this, Muhammad received news that an army was marching from Hulwan to take al-Ahwaz; in response, he gathered his own forces and advanced north to 'Askar Mukram.
When Muhammad saw that he was losing the fight, he and several of his freedmen dismounted, hamstrung their horses and charged at Tahir's men, killing many of them.
In the midst of the charge, however, Muhammad was hit by a spear and fell; a group of enemy soldiers then rushed him and struck him until he was dead.