Sultan Mahmud, the 24th Ottoman Sultan, was proclaimed the new Sultan after the dethronement of his uncle, Ahmed III. At the time of his accession to the throne, the Safavid Wars and the Patrona Khalil Rebellion were raging in Istanbul. After Mahmud I ended the Patrona Rebellion, he made peace with the Safavids after prolonged fighting, and Nadir Shah overthrew the Safavid Empire and established the Afsharid Dynasty. The Ottoman Empire fought simultaneously against Russia and Austria on two fronts, defeating these two great powers and achieving significant territorial gains. The Treaty of Belgrade also saw the recapture of Belgrade. Although the Afsharid Wars resumed, these were also resolved through the terms of the Treaty of Qasr-ı Şirin.