Harthama ibn A'yan had first appeared during…
September 808 CE
Harthama ibn A'yan had first appeared during the reign of the second Abbasid Caliph, al-Mansur (reigned 754–775), as one of the supporters of the Abbasid prince and heir-apparent Isa ibn Musa.
Isa had been forced to renounce his claim on the throne in favor of al-Mansur's son, al-Mahdi (r. 775–785), who had Harthama brought to Baghdad in chains and kept him under arrest throughout his reign.
Under al-Mahdi's son and successor al-Hadi (r. 785–786), however, he was released and rose to prominence as one of the Caliph's closest advisors.
At one point he is said to have recommended that the Caliph should execute his younger brother and heir-apparent, the future caliph Harun al-Rashid (r. 786–809) to open the path for the succession of al-Hadi's own sons, but this plan had been foiled through the intervention of the Caliph's mother, al-Khayzuran.
Nevertheless, when al-Hadi died it was Harthama himself who had released Harun from prison.
He has continued to enjoy a privileged position and high office under Harun as well, serving as governor of Palestine, Egypt, Mosul and then Ifriqiya, before assuming command of the caliphal guard (haras) under the supervision of Harun's trusted vizier, Ja'far ibn Yahya the Barmakid.
From this post he had played a role in the downfall of the Barmakids in 803, and had established himself as one of the Caliphate's senior military leaders.
He also led two summer raids into Asia Minor against the Empire.
When the large-scale rebellion of Rafi ibn al-Layth broke out in Khurasan in 805–806 and the local governor, Ali ibn Isa ibn Mahan, proved himself incapable of suppressing it, al-Rashid had sent Harthama to replace him, following himself shortly after, in 808.