Rafi was originally in the service of the Tahirids, which controlled Khurasan as virtual viceroys in the name of the Abbasid Caliphate. Tahirid (and implicitly also Abbasid) control of Khurasan was challenged in the 860s by the revolt of Ya'qub al-Saffar, who, beginning from his home province of Sistan, defeated the Tahirid armies and by 873 had seized the provincial capital, Nishapur. The failure of Ya'qub to seize Baghdad in 876, however, and his death soon after weakened the Saffarid regime that his brother Amr ibn al-Layth inherited.
With the Saffarids engaged elsewhere, and their takeover of the former Tahirid domains condemned as illegal by the Abbasid government, Nishapur was seized in 875 by an anti-Saffarid faction under Ahmad ibn Abdallah al-Khujistani, a former Tahirid soldier. After his murder in 882, Rafi, who had risen to be his commander-in-chief, was acclaimed by al-Khujistani's army as his successor. Rafi faced the opposition of the Saffarids under Amr, who had made his peace with the caliph in 879 and been recognized as governor of Khurasan and most of Iran, as well as the adventurer Abu Talha Mansur ibn Sharkab, who had briefly seized Nishapur in 876–878 and was now ruler of Merv. Defeated, Abu Talha soon sought Samanid and Saffarid aid, and in 885 he was appointed as the Saffarid deputy for Khurasan, while Amr turned again west to confront the attempts of the Abbasid regent, al-Muwaffaq, to recover Fars.
At this point, Rafi's fortunes changed, as al-Muwaffaq stripped the Saffarids of their governorships, and conferred Khurasan on Rafi. Rafi was now able to secure an alliance with the Samanids of Transoxiana and neutralize Abu Talha, seizing Merv and Herat. He raided as far as Khwarezm in 886 and aided the Samanid Isma'il ibn Ahmad against his brother Nasr I. In 888/889 Rafi invaded and conquered the Zaydid domains of Gurgan and Tabaristan, defeating the Zaydid ruler Muhammad ibn Zayd in battle at the Chalus River. From Tabaristan he marched to Qazvin and then Rayy in 889/890, where he established his headquarters until al-Muwaffaq's death in June 891. During his stay in Tabaristan, Rafi was joined by Ali ibn al-Layth, Amr's brother, who had initially been the favoured candidate to succeed Ya'qub. Ali's sons, al-Mu'addal and al-Layth, would later accompany Rafi in his attempt to regain control of Khurasan in 896.
With the death of al-Muwaffaq and the rise to the regency (and soon to the throne) of his son, al-Mu'tadid, Rafi's fortunes changed again: al-Mu'tadid's policy of re-establishing caliphal authority in the western Caliphate required him to maintain friendly relations with Amr ibn al-Layth in Iran, and Rafi's control of Rayy threatened the province of Jibal, which al-Mu'tadid soon recovered from its semi-independent Dulafid governors. As a result, al-Mu'tadid invested Amr with the governorship of Khurasan, ordered Rafi to evacuate Rayy, and sent an army under Ahmad ibn Abd al-Aziz ibn Abi Dulaf against him. Evicted from Rayy, in order to gain allies for an attempt to recover Khurasan, Rafi reconciled himself with Muhammad ibn Zayd, to the extent that he had the Friday prayer read in the latter's name. This turn towards the Alids marked a public break with the Abbasid and Sunni camp, which the Saffarids exploited accordingly to bolster their support among the populace of Khurasan. In 896, Rafi invaded Khurasan and captured Nishapur, where too he had the prayer read in Muhammad's name. He even adopted Alid white instead of Abbasid black for his colours. The help promised by Muhammad ibn Zayd, however, never arrived, and Rafi was soon expelled from the city by the Saffarids. His forces were defeated at Bayhaq and Tus, and finally driven out of Khurasan to Khwarazm, where Rafi was defeated and killed in a final battle. His severed head was dispatched to Baghdad.
- Bosworth (1995), p. 385
- Kennedy (2004), pp. 159–160
- Bosworth (1975), pp. 90, 95–104
- Kennedy (2004), pp. 175–176
- Bosworth (1975), pp. 112–115
- Kennedy (2004), p. 176
- Bosworth (1975), p. 116
- Bosworth (1975), p. 118
- Bosworth (1975), pp. 116–119
- Bosworth (1975), pp. 118, 120
- Bosworth (1975), pp. 116, 118, 120
- Kennedy (2004), pp. 179–183
- Bosworth (1975), p. 120
- Bosworth, C.E. (1975). "The Ṭāhirids and Ṣaffārids". In Frye, R.N. (ed.). The Cambridge History of Iran, Volume 4: From the Arab Invasion to the Saljuqs. Cambridge: Cambridge University Press. pp. 90–135. ISBN 0-521-20093-8.
- Bosworth, C. E. (1995). "Rāfiʿ b. Hart̲h̲ama". In Bosworth, C. E.; van Donzel, E.; Heinrichs, W. P. & Lecomte, G. (eds.). The Encyclopaedia of Islam, New Edition, Volume VIII: Ned–Sam. Leiden: E. J. Brill. p. 385. ISBN 978-90-04-09834-3.
- Kennedy, Hugh N. (2004). The Prophet and the Age of the Caliphates: The Islamic Near East from the 6th to the 11th Century (Second ed.). Harlow, UK: Pearson Education Ltd. ISBN 0-582-40525-4.