various Iranian empires would control their Caucasian provinces, all the way up to Dagestan in the early 19th century. In the meantime, between 1514 and 1603, the Ottomans sometimes occupied Tabriz and other parts of the province during their numerous wars with their Safavid ideological and political archrivals. The Safavid control was restored by Shah Abbas but during the Afghan invasion (1722–8) the Ottomans recaptured Azerbaijan and other western provinces of Iran, until Nader Shah expelled them. At the beginning of the reign of Karim Khan Zand, the Azad Khan Afghan unsuccessfully revolted in Azerbaijan and later the Dumbuli Kurds of Khoy and other tribal chiefs ruled various parts of the territory. Azad Khan was defeated however by Erekle II. With the advent of the Qajars, Azerbaijan became the traditional residence of the heirs-apparent. Even until then Azerbaijan remained the main area from where the high-ranked governors would control the various territories and Khanates of the Caucasus while the main power stayed in Tehran. Though the first Qajar Iranian ruler, Agha Mohammad Khan, had reconquered the Caucasus and all of Iran in several swift campaigns, such as the harsh re-subjugation of Georgia in 1795, Iran would eventually irrevocably lose all of the Caucasus region to neighbouring Imperial Russia during the course of the 19th century, which had a crucial impact on the region of modern-day Iranian Azerbaijan. Shortly after the reconquest of Georgia, Agha Mohammad Shah was assassinated while preparing a second expedition in 1797 in Shusha. The reassertion of Iranian hegemony over Georgia did not last long; in 1799 the Russians marched into Tbilisi, which would mark the beginning of the end of the Iranian-ruled domains in the Caucasus, comprising modern-day Georgia, Armenia, the Republic of Azerbaijan, and Dagestan thanks to the 19th century Russo-Persian Wars. Since the late 17th/early 18th century, the Russians were actively pursuing an expansionist policy towards its neighbouring empires to its south, namely the Ottoman Empire and the successive Iranian kingdoms. Agha Mohammad Khan's death and the Russian troops entering the Iranian possession of Tbilisi in 1799, led directly to the Russo-Persian War (1804-1813), the first of a number of Russo-Persian wars during the 19th century, and the most devastating and humiliating one. By the end of the war in 1813 and the resulting Treaty of Gulistan, Qajar Iran was forced to cede Georgia, most of the modern-day Republic of Azerbaijan, and Dagestan to