In early 811, with the outbreak of civil war between al-Amin and his brother al-Ma'mun (), who had been given a large viceregal domain encompassing Khurasan, al-Amin entrusted Ali with the subduing al-Ma'mun and his followers. At the head of a huge army of reportedly 50,000 men drawn from the "abna", Ali marched east, but in the Battle of Rayy on 3 July 811 he was crushingly defeated and killed by a far smaller army of al-Ma'mun under Tahir ibn al-Husayn.