After joining the caliphal court, al-Afshin quickly became one of the leading figures in the Abbasid military establishment. During the caliphate of al-Ma'mun, he was sent to Barqa and, in 831, to Egypt, in order to suppress rebel activity in those provinces. After al-Mu'tasim became caliph, he was given a major command as the leader of the war against Babak al-Khurrami in Adharbayjan, and after a two-year campaign (835–837) he succeeded in destroying the rebellion and capturing its leader. Following this, he was put in charge of part of the Muslim army during al-Mu'tasim's 838 expedition against the Byzantines, and he played a leading role during the siege of Amorium. The exact composition of his forces during these campaigns is unknown, but it appears that both Ushrusani and non-Ushrusani officers were serving under him by the mid-830s.