ibn al-Muqtadir along with Ray, Dinavar, Zanjan, Abhar, and Tarom. In 916/7 (304 AH), Yusuf ibn Abi'l-Saj unsuccessfully attempted to seize control of Qazvin. He was defeated by Asfar ibn Shiruya, who made himself ruler of the whole region between Tabaristan and Gorgan and Qom and Hamadan. In 927/8 (315 AH) Qazvin was the site of a battle between Asfar and an army sent by the Abbasid caliph al-Muqtadir against him. The people of Qazvin assisted the Abbasid army, but Asfar won the battle. As punishment for siding against him, Asfar destroyed parts of the city, killed many of its inhabitants, and imposed monetary demands on the city. After Asfar's death, the Buyid ruler Rukn al-Dawla took control of Qazvin, and it remained part of Buyid territory for over a hundred years. There was rioting in the city in 968/9 (358 AH) and the Buyid vizier Abu'-Fath Ali ibn Muhammad was sent to restore order. When that was done, he imposed a fine of 1,200,000 dirhams on the city. Ghaznavids, Seljuks, and Khwarazmshahs Qazvin came under Ghaznavid control in 1030 (421 AH). Around 1033/4 (424 AH), Abu Ali Muhammad Ja'fari became governor of Qazvin. He and his sons continued to hold power in Qazvin for almost 60 years. The last of these sons, Fakhr ul-Ma'ali Sharafshah, died in 1091 or 1092 (484 AH) and was survived by one daughter. He was extremely wealthy and he and his followers owned most of the land in the area. The annual income from his landed estates was said to be 366,000 gold dinars. In 1038/9 (430 AH), along with an alliance of the Ghuzz, the Daylamite ruler Fanna Khusraw came to Qazvin after already sacking Ray the year before. The locals bought them off for a sum of 7,000 dinars. Later in 1042/3 (434 AH), the Seljuk sultan Tughril besieged Qazvin. In 1046 Qazvin was visited by Nasir-i Khusraw, who left the following account: Under the Seljuks, Qazvin appears to have formed part of the central territory around the capital in Isfahan that was more or less directly ruled by the sultans, who were able to levy taxes and appoint governors here. However, despite Qazvin's position close to the Isma'ili strongholds like Alamut, the Seljuks do not seem to have considered it an important governorship to be given to an important amir. After the death of the last Ja'fari ruler of Qazvin, Malikshah