In 1667, the Russo-Polish war ended with the Treaty of Andrusovo, which split the Cossack Hetmanate along the Dnieper River: Left-bank Ukraine enjoyed a degree of autonomy within the Tsardom of Russia, while Right-bank Ukraine remained part of the Polish–Lithuanian Commonwealth, and was temporarily occupied by the Ottoman Empire in the period of 1672-1699 ("see" the Treaty of Buchach and the Treaty of Karlowitz). For a short time, Petro Doroshenko became the hetman of both banks. After treason by Demian Mnohohrishny and a new Polish offensive Dorosenko concluded an alliance with the Ottomans, who granted him Ukraine, while the hetman agreed to support Ottoman military action with his army. "By 1669 the Porte issued a patent (berat, nişan) granting Doroshenko all of Cossack Ukraine as an Ottoman sancak or province". After the defeat of the Ottomans at the Battle of Vienna in 1683, Poland managed to recover right-bank Ukraine by 1690, except for the city of Kiev, and reincorporated it into their respective voivodeships of the Polish–Lithuanian Commonwealth, while all the Hetmanate administration was abolished between 1699 and 1704.