rule. In 916 or 917, Abhar (along with Zanjan, Qazvin, and Ray) was seized from the Samanids by the Sajid Yusuf ibn Abi'l-Saj (), the virtually independent governor of the caliphal provinces of Azerbaijan and Armenia. Yusuf attempted to justify his attack by claiming that the previous caliphal vizier Ali ibn Isa ibn al-Jarrah had given him the governorship of the region. Most authors, however, consider this claim to be made up. In 917, Wasif al-Baktimuri was given the governorship of Abhar and other areas by the caliph al-Muqtadir (). In 928, Abhar was briefly seized by the Alid ruler of northern Iran, Abu Muhammad Hasan ibn Qasim. He was soon ousted from the town by Asfar ibn Shiruya, who claimed the place for himself. In 930, Asfar was betrayed and ambushed by his Ziyarid commander Mardavij, who took over his domains, including Abhar. In 942, the Samanid general Abu Ali Chaghani captured Abhar. In 997, the ruler of the Daylamite Sallarid dynasty, Ibrahim II ibn Marzuban II, capitalized on the weak rule of the Buyid ruler Majd al-Dawla () by briefly seizing Buyid land in Jibal, including Abhar, Zanjan and Sohrevard. A coin that was struck in 1013/14 has been found in Abhar, either made under the Sallarids or their opponents, the Rawadid dynasty. In 1029, Abhar was conquered by a Ghaznavid force led by prince Mas'ud. In 1091, the Nizari Ismailis seized Sanamkuh, a fortress located in the environs of Abhar. They controlled until 1096, when they were repelled by the sultan of the Seljuk Empire, Berkyaruq (). In 1167, Abhar was attacked by a force led by Inanaj, a commander of the Eldiguzid dynasty of Azerbaijan. Supported by soldiers sent by the Khwarazmshah Ala al-Din Tekish () of the Anushtegin dynasty, Inanaj ran rampant in the town, capturing the women and children before going back to Khwarazm. In 1217, the Khwarazmshah Muhammad II () conquered Abhar. Abhar is described in some detail by Hamdallah Mustawfi, who in the 14th-century served as governor of the town along with some other places. He estimated that the length of the ramparts was 5,500 gams (paces/strides). He commended the produce of the town, which encompassed of grain and large amount of fruits, especially the Sijistani pears, Bu Ali plums and black cherries. He also reported that the residents of Abhar had fair skin and were adherants of the Shafi'i school, and