Khanates of late 18th – early 19th centuries
While civil conflicts took hold in Iran, most of Azerbaijan was occupied by the Ottomans (1726 to 1736). Meanwhile (from 1722 until 1735), during the reign of Peter the Great, the coastal strip along the Caspian Sea comprising Derbent, Baku and Salyan came under Imperial Russian rule.
After the collapse of the Safavid empire, Nadir Shah Afshar (Nadir Guli Bey), a former slave who had risen to military leadership within the Afshar Turkoman tribe in Khorasan (a vassal state of the Safavids) came to power. He wrested control over Iran from the Afghans in 1729 and proceeded to go on an ambitious military spree, conquering as far as east as Delhi, but not fortifying his Persian base and exhausted his army. Nadir had effective control over Shah Tahmasp II and then ruled as the Regent of the infant Abbas III, until 1736, when he had himself crowned as Shah. The coronation of Nadir Shah took place in Mughan, in the present territory of Azerbaijan, where the Azeri military and tribal aristocracy gathered.
After Nadir Shah's assassination in 1747, the Persian Empire under Afsharids disintegrated.Several Muslim khanates, described as Azerbaijani by some sources and as Iranian by others,became de facto independent while remaining under nominal Persian suzerainty. The khanates engaged in constant warfare between themselves and with external threats. The most powerful among the northern khans was Fat'h Ali Khan of Quba (died 1783), who managed to unite most of the neighboring khanates under his rule and even mounted an expedition to take Tabriz, fighting with Zand dynasty. Another powerful khanate was that of Karabakh, which subdued neighboring Nakhchivan khanate and parts of Erivan khanate.
By 1796, Agha Muhammed Khan Qajar raided and conquered Azerbaijan and Georgia. Some khanates made the fateful decision to ask for Russian help, while other Azeris were content with Qajar rule. However, the Russians, who by this time controlled Georgia, had already subjugated most of the khanates in the Caucasus by 1806. The Qajars responded to these events by declaring war, which continued until 1813 when Russians invaded Tabriz.
The khanates exercised control over their affairs via international trade routes between Central Asia and the West. Engaged in constant warfare, these khanates were eventually incorporated into the Russian Empire in 1813, following the two Russo-Persian Wars. The area to the North of the river Aras, among which the territory of the contemporary republic of Azerbaijan were Iranian territory until they were occupied by Russia. Under the Treaty of Turkmenchay, Persia recognized Russian sovereignty over the Erivan Khanate, the Nakhchivan Khanate and the remainder of the Lankaran Khanate..