At the end of the 16th and the beginning of the 17th century Azerbaijan fell under the control of the Ottomans, and after the assassination of Nadir Shah in 1747 more than 20 small Azerbaijani Khanates emerged, including Bakı, Cavad, Dərbənd, Gəncə,
İrəvan, Lənkəran, Naxçıvan, Qarabağ, Quba, Şəki, Şirvan and Talış in the north, and Ərdəbil, Xoy, Marağa, Maku, Qaradağ, Sərab, Təbriz, and Urmiya in the south.
Nagorno-Karabakh, home to both Azerbaijani Muslims and Caucasian Albanian Christians, part of the Azerbaijani khanate of Qarabağ (Karabakh), which stretched between the Kür and Araz Rivers. In addition, the local Caucasian Albanian princedoms, called melikdoms (məlikliklər) of Dizak, Gülüstan, Xaçın, Çiləbörd and Vərəndə were also parts of the Qarabağ khanate.
The khanates engaged in constant warfare for domination of the land, and this discord helped Russia and Persia realize their plans to conquer Azerbaijan. A group of khanates took up arms to defend their independence, but the resistance was in vain in the face of the better-equipped armies of Russia and Persia.
On May 14, 1805, on the banks of the Kür River at a place called Kürəkçay, the Azerbaijani khan, Ibrahim Khalil Khan, ruler of Qarabağ, was forced to sign a treaty of surrender with the Russian Empire under which the independent Qarabağ Khanate accepted the Russian sovereignty. Even today this treaty has not lost its historical significance because it establishes that Qarabağ has historically been an Azerbaijani territory.
In 1828, after a protracted war of conquest between Russia and Persia, a treaty was signed in Türkmənçay (Turkmenchay) near Təbriz. The Treaty of Türkmənçay, which was the second treaty signed by these two powers in their Caucasian Wars, had far-reaching consequences. The first treaty, signed in Gülüstan in 1813, had resulted in the first partition of Azerbaijan, and under the 1828 treaty all of Northern Azerbaijan, mainly north of the Araz River, as well as the regions of Muğan and Talış became a part of Russia, while the areas to the south of the river fell to Persia. To secure its rule in the South Caucasus, Russia resettled approximately 200,000 Armenians from Iran and eastern Turkey mainly in Nagorno-Karabakh (about 124,000), but also in Naxçıvan and Yerevan. In 1836, the Armenian Gregorian church persuaded the Russians to dissolve the Caucasian Albanian Patriarchy that still existed in Azerbaijan and to turn its property over to the Armenian Church. Thus, all the Caucasian Albanian churches and places of worship in Nagorno-Karabakh were Gregorianized/Armenianized.
Beginning from the mid-19th century the oil industry in Azerbaijan started to rapidly develop. In 1848 – more than a decade before Americans made their famous discovery of oil in Pennsylvania – Azerbaijan drilled the world’s first oil well in the fields of Bibi-Heybət, just south of Bakı. In the late 19th-early 20th centuries, Bakı was already producing 95% of the Russian Empire’s and about 50% of the world’s oil production. Famous Western entrepreneurs such as the Nobels and Rothschilds were among the oil magnates of Bakı.
Due to this oil boom Bakı was quickly internationalized and industrialized. The population of Bakı increased, and it became the largest city in the Caucasus. The growth of Bakı and the progression of an exploitative economy resulted in the emergence of an Azerbaijani nationalist intelligentsia that was educated and influenced by European ideas. Influential thinkers like Hasan bey Zardabi, Mirza Fatali Akhundzade and later, Jalil Mammadguluzadeh, Mirza Alakbar Sabir, Nariman Narimanov and others spurred a nationalist discourse and rallied against poverty, ignorance, extremism and sought reforms in education and the emancipation of the dispossessed classes, including women. The financial support of philanthropist millionaires such as Haji Zeynalabdin Taghiyev also bolstered the rise of an Azerbaijani middle-class. The Russian Revolution of 1917 (the October Revolution) and the collapse of the Russian Empire offered Azerbaijan the opportunity it had waited for so long.