In 1106, the Seljuq Sultan Muhammad I conquered the Ismaili fortress of Shahdiz, and ordered Shahriyar IV to participate in the campaign against Ismailis. Shahriyar, greatly angered and feeling offended by the message Muhammad sent him, refused to aid him against the Ismailis. Shortly after the sultan sent an army headed by Amir Chavli who tried to capture Sari but was defeated in an unexpectedly defeated by an army under Shahriyar and his son Qarin III. Muhammad then sent a letter, which requested Shahriyar to send one of his young sons to the Seljuq court in Isfahan. He sent his son Ali I, who impressed Muhammad so much that he offered him his daughter in marriage, but Ali refused and told him to grant the honor to his brother and heir of the Bavand dynasty, Qarin III. Qarin III then went to Isfahan court and married her. After his return to Sari, however, he began claiming the Bavand throne for himself, and started abusing his father Shahriyar and his servants. Shahriyar then moved to Amol and later Rudsar, where he built a Khanqah, and devoted himself to religion. However, when he got sick, Qarin III apologized and restored him as the ruler of the Bavand dynasty. Qarin III's refusal to submit to the Seljuq atabeg of Ray, made the atabeg offer Ali an opportunity to conquer Mazandaran, to which he agreed. Shahriyar quickly sided with Qarin III and convinced Ali to withdraw. Nevertheless, the strife continued between the two brothers. Ali later went to Marw and joined the Seljuq prince Ahmad Sanjar, the ruler of Khorasan. Ahmad Sanjar was preparing for an expedition to the west in order to take control of Gorgan, but an attack made by Muhammad Khan on the Seljuq borders, forced Ahmad Sanjar to move east in order to repel Muhammad Khan. This allowed Qarin III to capture Gorgan while Shahriyar stayed in Tamisha. Shahriyar later fell ill and died in 1117, and was succeeded by Qarin III. After having ascended the Bavand throne, he arrested and imprisoned many of the most loyal servants of his father. These actions heavily weakened the Bavand kingdom. Qarin later fell ill, and died after he asked the localpeople to pledge allegiance to his son Rustam III, who succeeded Qarin as the ruler of the Bavand kingdom.