Mazyar belonged to the Qarinvand dynasty, which was descended from Sukhra, a powerful magnate from the House of Karen, who was the de facto ruler of the Sasanian Empire from 484 to 493. However, due to his great influence and power, he was exiled and executed by the Sasanian king Kavadh I. Sukhra was survived by eight sons, one of them being Karin, who in return for aiding Kavadh I's son and successor Khosrow I against the Western Turkic Khaganate in the 550s, received land to the south of Amol in Tabaristan, thus starting the Qarinvand dynasty.
Accession, flight, and rise to power
Mazyar succeeded his father Qarin ibn Vindadhhurmuzd in ca. 817. However, his territories were soon invaded by the neighbouring Bavandid ruler Shahriyar I, who defeated Mazyar and forced him to flee. Mazyar took refuge with his cousin Vinda-Umid, who betrayed him and handed him over to Shahriyar. However, Mazyar managed to escape and reach the court of the Abbasid caliphal-Ma'mun. There he met one of his astrologers, Yahya ibn al-Munajjim, a Persian who had recently converted to Islam and belonged to the Banu Munajjim family. Mazyar soon also embraced Islam, and al-Ma'mun gave him the title of "Servant of the Commander of the Faithful" and the Muslim name of Abu'l-Hasan Muhammad. Mazyar was also granted two towns of Ruyan and Damavand in Tabaristan as his fief, and was named as the co-governor of Tabaristan with the Abbasid statesman Musa ibn Hafs. In 822/3, Mazyar returned to Tabaristan with Abbasid reinforcements, and began to deal with his enemies—he had his brother Quhyar exiled, and did the same to Shahriyar I's son Qarin I, who was his nephew. In 825/6, Mazyar invaded the domains of the Bavandids, and captured Shahriyar's son and successor, Shapur. His uncle, Vinda-Umid, was also defeated, and shortly afterwards killed. Mazyar thus united the highlands under his own rule. He then assumed the titles of Gil-Gilan, Ispahbadh, and Padishkhwargarshah, all titles used by the 8th-century Dabuyidking of Tabaristan, Farrukhan the Great.
Reign
Early rule as ''Ispahbadh'' of Tabaristan
Shapur, knowing that Mazyar planned to have him killed, sent a secret message to Musa, willing to pay him 100,000 dirhams if he would assert him as his own prisoner. Musa responded by saying his best shot would be to convert to Islam and become a client of the caliph. Musa, nervous of Mazyar learning of his secret communication with Shapur, asked him how he would react if Shapur converted to Islam and offered to become a client of the caliph. Mazyar gave no answer, but had Shapur beheaded the same day, which greatly angered Musa. Mazyar, fearful of the consequences of having Shapur killed without consensus, apologized to Musa. Mazyar now began constructing mosques in several towns, and successfully plundered the territories of the Daylamites, and had a large number of them resettled in the border place of Muzn. In 826/7, Musa died and was succeeded by his son Muhammad ibn Musa, to whom Mazyar paid no attention. Mazyar continued to expand his influence, but his policies were regarded by the Muslims of Tabaristan as oppressive. The Muslims of Tabaristan and the Bavandid prince Qarin I now began complaining to al-Ma'mun about Mazyar's behavior, but did not manage to turn al-Ma'mun against Mazyar. After al-Ma'mun became involved in a war against the Byzantine Empire, Mazyar used the opportunity to imprison Muhammad ibn Musa on the charge of being secretly involved with the Alids. Al-Ma'mun soon acknowledged Mazyar's rule over Tabaristan and its surrounding regions. When al-Ma'mun died in 833, he was succeeded by his half-brother al-Mu'tasim, who also acknowledged Mazyar as the ruler of Tabaristan. However, when the Tahirid ruler Abdallah ibn Tahir demanded the payment of the land tax from Mazyar, the latter refused. Abdallah, claiming Tabaristan as his own fief, then demanded that Mazyar should release Muhammad ibn Musa. Mazyar, however, once again refused to obey Abdallah, and the latter went before al-Mu'tasim to accuse Mazyar of infidelity and tyranny.
Rebellion
Feeling threatened, Mazyar rebelled against the Abbasid Caliphate, an act which was widely supported by the native Zoroastrians, who began plundering the Muslim villages and the Abbasid-controlled border regions. Mazyar tried to secure the loyalty of the noblemen of Tabaristan and imprisoned anyone he did not trust. According to the medieval historianIbn Isfandiyar in his Tarikh-e-Tabaristan, Mazyar is said to have proclaimed: Abdallah and al-Mu'tasim sent five armies that entered Tabaristan from all sides. Mazyar named his brother Quhyar as the defender of the Qarinvand mountains, and the Bavandid Qarin I as the defender of eastern Tabaristan. However, Tabaristan fell quickly to the Abbasid invasion: several cities were taken by surprise, while Qarin I betrayed Mazyar and agreed to aid the Abbasids in exchange for being restored as the ruler of his family's domains. The people of Sari revolted against Mazyar, and Mazyar was betrayed by his brother Quhyar, who captured him and surrendered him to al-Mu'tasim. Mazyar was brought to Samarra, where he was executed. His body later was gibbeted along with the body of Babak Khorramdin. Mazyar's brother Quhyar was shortly after killed by his own Daylamite soldiers because of his betrayal of Mazyar. This marked the end of the Qarivand dynasty. This left the Tahirids as the rulers of Tabaristan, and Qarin I was restored as the ruler of the Bavand dynasty as a vassal.