Born to a Zoroastrian family native to Gilan, Mardavij was an anti-Muslim, who sought to revive the Sasanian Empire which was conquered in the 7th century by the Muslims. He first started his career by joining the army of his kinsman Asfar ibn Shiruya. Mardavij, however, later betrayed and killed him, conquering much of Jibal. He then set out to conquer Hamadan, Dinavar and Isfahan from the Abbasid Caliphate, and thereafter declared himself king of Iran, making Isfahan his capital.
He then defeated the Daylamite military leader Makan ibn Kaki, and conquered Tabaristan in 932. By 934, his authority was acknowledged as far as Shiraz and Ahvaz. However, his goal of recreating the Persian Empire was ruined when he was murdered by his own Turkish slaves in 935.
Mardavij was born ca. in 890 in Gilan; he was the son of Ziyar, who belonged to the Shahanshahvand, a royal clan that roamed in Dakhel. Mardavij's mother was a sister of Harusindan, a Gilaki ruler. Mardavij belonged to the Arghich tribe, which claimed to be descended from Arghush Farhadan, king of Gilan who lived during the time of Kay Khosrow. Mardavij grew up in an environment where "Persian culture, memories of the glories of the Persian Empire, were alive among them." According to the 10th-century Arab historian al-Masudi, most of the Daylamite and Gilaki leaders, who were Zoroastrian and pagan, had become atheists. Mardavij was one of the many Gilaki leaders that entered into the service of the Alids, after establishing their rule over Tabaristan, Gilan, and Daylam.
Around 913, Mardavij joined the army of Asfar ibn Shiruya, a military leader from Lahijan, who served the Zaydids of Tabaristan. In 930, Asfar invaded the domains of the Zaydi Abu Muhammad Hasan ibn Qasim. During the invasion, Mardavij managed to heavily wound Abu Muhammad near Amol, thus avenging his maternal uncle Harusindan, who was killed by the hands of the Alids. The army of Asfar then marched towards Ray, where they defeated the Daylamite general Makan ibn Kaki, who fled to Daylam. Asfar managed to successfully conquer Tabaristan, and also captured Qazvin and Zanjan. He then appointed Mardavij as the governor of Zanjan. In 930, Mardavij along with Asfar's brother, Shirzad, were ordered to capture Tarom, the capital of the Sallarid ruler Muhammad bin Musafir. During the siege, Mardavij, on the urging of Makan and Muhammad, betrayed Asfar by revolting against him. With the aid of Muhammad and Makan, Mardavij defeated and killed Shirzad, including other members of his tribe. He then marched towards Qazvin, the residence of Asfar. However, Asfar managed to flee. Mardavij thus founded the Ziyarid dynasty, and became ruler of Asfar's former territories, which included; Ray, Qazvin, Zanjan, Abhar, Qom and Karaj. He is said to have worn a "crown of Anushirvan" at his court.
In the same year, Makan managed to defeat Mardavij, and briefly recover Tabaristan. Makan then extended his rule over most of Gurgan and even take possession of Nishapur in western Khurasan, which he was forced to abandon in 931, bowing to pressure by the Samanid ruler Nasr II. In 931, Mardavij sent an army against Makan, but the latter defeated Mardavij's forces in a first engagement in 931. Eventually, after Makan's return to Tabaristan from Nishapur, Mardavij personally launched an attack that conquered Tabaristan.