At the end of XVIII–beginning of XIX cc. the political situation in Azerbaijan was very hard. On one hand, this was preconditioned by the socio-economic backwardness and feudal dissociation of the country, and on the other hand- aggression of the neighbouring powers – Russian and Ottoman Empires and Iran.
Already in 1801 when the Eastern Georgia was incorporated into the Russian Empire, the soltanats (feudal possessions) of Kazakh and Shamshadil, which were under the vassal dependence from Georgia, were annexed to Russia as well. This was the beginning of the incorporation of the North Azerbaijan into Russia. In 1803 and 1804 the Russian troops occupied Djar-Balaken in the northern and an important city of Ganje in the central Azerbaijan. Russian advance seriously worried Iran, which declared war against Russia in June 1804.
At this time Ibrahim Khalil khan of Karabakh, like many other rulers of Azerbaijan faced a dilemma: whom to support in this war- Russia or Iran. After not long period of hesitation, Ibrahim Khalil khan proceeding from the power correlation between the two regional powers, and also the past difficult relations with Iran decided to join to the alliance with Russia.
On May 14, 1805 in a locality called Kurekchai near Ganje there was signed an “obligation of oath” (the Kurekchai Treaty) between Ibrahim Khalil khan- the ruler of Karabakh and the commander-in-chief of the Russian troops in the Caucasus knyaz Sisianov. According to the Kurekchai Treaty the Karabakh khan recognized dependence on the Russian Empire, gave up his right to carry out independent foreign policy and took obligation to pay the Russian Treasury 8 thousand gold chervons a year. In its turn, the Czarist government took obligation not to infringe the right of the legitimate successors of the Karabakh khanate to administer the internal affairs of their possessions.
Thus, the territory of Karabakh entered Russia, as indicated in the text of the treaty, as a “Muslim (i.e. Azeri) possession”.
In June 1806 during the Iranian troops’ offensive to Karabakh, there took place an incident, which had very negative effect on the fate of all future Azeri khanates within the Russian Empire. Having got news about the approaching Iranian troops, Ibrahim Khalil khan asked the commander-in-chief of the Russian army in the Caucasus to send to Karabakh more military force in order to reinforce the Karabakh militia and approximately 500 Russian soldiers headed by the major Lisanevich. Not having got reinforcement and considering the fact that the advancing Iranian troops had a great advantage in number, Ibrahim Khalil khan, together with the members of his family, left the Shusha fortress and camped in its suburbs with purpose to have way to retreat in case of the unfavorable result of the upcoming battle with Iranians to him and his Russian allies. Major Lisanevich, the head of the Russian military detachment in Karabakh greatly misunderstood this move of Ibrahim Khalil khan and considered this as a betrayal in favor of the Iranians. He suddenly attacked to the Ibrahim Khalil khan’s camp and brutally killed the khan of Karabakh and the members of his family who were together with him. This brutal violence have caused a great indignation in Azerbaijan and increased distrust of the Azerbaijanian rulers to Russians. The Baku and the Kuba khanates refused to submit to the Russians in goodwill. The ruler of the Sheki khanate renounced previous agreement with the Russians and expelled them from the territory of Sheki khanate. In Djar-Balaken insurrections against the Russian supremacy took place as well.
All these insurrections were suppressed soon. As a consequence of all these incidents the Baku, Kuba and Derbent khanates were abolished. The rulers of the rest of the khanates of the North Azerbaijan, which depended on Russia, were toppled down and new khans were appointed in their place. The Karabakh khanate also was among them. Here Ibrahim Khalil khan’s son Mehdikulu khan was appointed a new ruler of Karabakh, but he appeared to be an untalented leader, which has predetermined the fate of the Karabakh khanate.
On October 12, 1813 in the village of Gulistan in the territory of Karabakh there was signed a peace treaty between Russia and Iran, which put and end to the Russo-Iranian was of 1804-1812. According to the peace treaty, the whole North Azerbaijan, except the Erivan and Nakhichevan khanates, which remained within Iran, were included within Russian Empire. Afterwards, as a result of a new Russo-Iranian war of 1826-1828 and the signed Turkmenchai treaty, Russia irrefutably strengthened its positions in the Caucasus, and the whole North Azerbaijan, this time also including the Erivan and Nakhichevan khanates, became a part of the Russian Empire.
By this time great changes have already took place in the administrative division of Azerbaijan: the khanates had been abolished and new provinces, governed by the commandants of the Czarist government, were created in their place. The Karabakh khanate was also eliminated in 1822. In its place there was created a Karabakh province, which was transformed to the Shusha district (uyezd) and included into the Caspian province later in 1840. In 1868 when the Yelizavetpol province (goubernia) was established (after occupation of Ganje it was renamed Yelizavetpol), the Shusha district was placed within this province. Consequently, from parts of the Shusha district there had been created new Zangezur, Jevanshir and Jebrayil districts, which also were included within the Yelizavetpol province. Such administrative division was preserved without considerable changes till 1921.