In 822 he was appointed as chief of security (shurtah) of Baghdad, and over the next three decades he oversaw many of the major developments in that city, including the implementation of the mihnah or inquisition, the removal of the Abbasid central government to Samarra, and the suppression of the attempted rebellion of Ahmad ibn Nasr al-Khuza'i. After his death, the shurtah of Baghdad briefly remained in the hands of his sons, before being transferred to the Tahirid Muhammad ibn 'Abdallah ibn Tahir in 851.