When Soltan Hoseyn was forced to abdicate by the Afghans in 1722, Prince Tahmasp wished to claim the throne.
[citation needed] From the besieged Safavid capital, Isfahan, he fled to Qazvin, where he on 10 November 1722 declared himself shah and assumed the regnal name of Tahmasp II.
[4] He gained the support of the Sunni Muslims of the Caucasus (even that of the previously rebellious Lezgins), as well as several Qizilbash tribes (including the Afshars, under the control of Iran's future ruler, Nader Shah).
In June 1722, Peter the Great, the then tsar of the neighbouring Russian Empire, declared war on Safavid Iran in an attempt to expand Russian influence in the Caspian and Caucasus regions and to prevent its rival, Ottoman Empire, from territorial gains in the region at the expense of declining Safavid Iran.
The Russian victory ratified for Safavid Irans' cession of their territories in the Northern, Southern Caucasus and contemporary mainland Northern Iran, comprising the cities of Derbent (southern Dagestan) and Baku and their nearby surrounding lands, as well as the provinces of Gilan, Shirvan, Mazandaran, and Astrabad to Russia per the Treaty of Saint Petersburg (1723).