In late 1077, Seljuk emir Tutush I launched a campaign to capture Aleppo during the reign of Sabiq ibn Mahmud of the Mirdasid dynasty, which lasted until 1080, when his reinforcements were ambushed and routed by a coalition of Arab tribesmen led by Kilabi chief Abu Za'ida at Wadi Butnan. After the death of Sharaf al-Dawla of the Uqaylid dynasty in June 1085, the headman in Aleppo Sharif Hassan ibn Hibat Allah Al-Hutayti promised to surrender the city to Tutush, but then refused and wrote to Sultan Malik-Shah I offering to surrender the city to him, Tutush attacked and occupied the city except for the citadel in May 1086, he stayed until October and left for Damascus due to the advance of Malik-Shah armies, the Sultan himself arrived in December 1086. In 1087, Aq Sunqur al-Hajib became the Seljuk governor of Aleppo under Sultan Malik Shah I.