The Zaydi tribesmen in the northern highlands particularly those of Hashid and Bakil, were ever the Turkish bugbear in all Arabia. The Ottomans who justified their presence in Yemen as a triumph for Islam, accused the Zaydis of being infidels. Hassan Pasha was appointed governor of Yemen and enjoyed a period of relative peace from 1585 to 1597. Pupils of al-Mansur al-Qasim suggested he should claim the imamate and fight the Turks. He declined at first, but the promotion of the Hanafi school of jurisprudence at the expense of Zaydi Islam infuriated al-Mansur al-Qasim. He proclaimed the imamate in September 1597, which was the same year the Ottoman authorities inaugurated al-Bakiriyya Mosque. By 1608, Imam al-Mansur (the victorious) regained control over the highlands and signed a truce for 10 years with the Ottomans. Imam al-Mansur al-Qasim died in 1620. His son Al-Mu'ayyad Muhammad succeeded him and confirmed the truce with the Ottomans. In 1627, the Ottomans lost Aden and Lahej. 'Abdin Pasha was ordered to suppress the rebels, but failed, and had to retreat to Mocha. Al-Mu'ayyad Muhammad expelled the Ottomans from Sana'a in 1628, only Zabid and Mocha remained under Ottoman possession. Al-Mu'ayyad Muhammad captured Zabid in 1634 and allowed the Ottomans to leave Mocha peacefully. The reason behind Al-Mu'ayyad Muhammad's success was the possession of firearms by the tribes and their unity behind him.