other Azerbaijani khanates. However, in 1789 following Fath Ali Khan's death, the Talysh Khanate regained its independence under Mir Mustafa, the son of Gara Khan who had himself died in 1786. In 1794-5 the Persian Shah Agha Muhammad Khan Qajar called on the various khanates of the South Caucasus to form an alliance against the Russian Empire and mounted a military expedition against those who refused to join him. The Talysh khanate refused to do and was attacked in 1795. Mir Mustafa Khan's disparate army was not strong enough to resist and he sent his representatives to General Gudovich asking for Russian protection. However, the Russians took a long time to respond, only finally arriving in 1802 when the Talysh Khanate became a protectorate of the Russian Empire. The khanate was to remain a pawn between the Persian and Russian empires over the subsequent two decades. In 1809 as a part of the Russo-Persian War (1804-1813), Iranian troops took the city of Lenkaran and expelled the Russian-leaning khan. In 1812, with Napoleon was attacking Moscow, the Russians were also battling again in the Caucasus. After a brief siege led by Pyotr Kotlyarevsky on January 1, 1813, 2,000 Russian troops managed to decisively take the citadel of Lenkaran from the Persian army. There were heavy losses on both sides, but this strategic capture of Lankaran led inexorably to September 12, 1813 Treaty of Gulistan. This forced defeated Persia to cede many of the formerly independent khanates to Russia. In 1814 Mir Mustafa khan died and his son Mir Hassan Khan succeeded him but only in name. With Russia busy in European wars, Persia attempted to reassert its hegemony in the area and to revert the Treaty of Gulistan and thus invaded the south Caucasus, starting the 1826-28 Russo-Persian war. In the campaign of 1826, Persia managed to regain all lost territories, but after the numerous defeats in the campaign of 1827, the war ended up with the even more humiliating Treaty of Turkmenchay which permanently ceded the Talysh Khanate to Russia. Yermolov took over the khanates of eastern Transcaucasia one by one and deposed their khans: Shaki in 1819, Shirvan in 1820, and Qara-Bagh in 1822. Only Mir Hassan Khan of Talesh was allowed autonomy, Ermolov understanding him and his family to be implacably hostile to Iran. In fact, Mir Hassan threw the Russians out in the year that hostilities reopened,