After a long siege, the Ganja Khanate was occupied by Tsarist Russia in January 1804, and Javad Khan, the Khan of the Ganja Khahate, and his son died heroic deaths in battle. After the occupation of the Ganja Khanate, Russian army general Gulyakov was sent from Jar-Balakan to Ganja. In March 1804, Tsar Alexander changed the name of Ganja to Yelizavetpol, in honour of his wife Yelizaveta.
The Tsarist Empire’s military attack on Azerbaijan affected its relations with the Persian and Ottoman empires. The Ottoman Empire was forced to remain silent, due to its 1798 agreement with the Tsarist Empire. The Persian Empire was faced with Tsarist aggression in the South Caucasus. Although it had forged an alliance with the rulers of certain Azerbaijani khanates, the Persian Empire was still looking for a new and powerful ally to help it stand up to the Tsarist Empire in the region. At the same time, European empires, especially Great Britain, were concerned at the southward expansion of the Tsarist Empire, which was viewed as a direct threat to its interests in the Middle East. European empires thus gave their full support to Iran in its war with the Tsarist Empire that broke out in June 1804.
At the time, the Karabakh Khanate, like other Azerbaijan khanates, was faced with one of the most serious political dilemmas and challenging situations in its history. Ibrahimkhalil Khan, who was trying to behave independently, had to make a choice between the Tsarist and the Persian Empires. According to Mirza Jamal Javanshir, who was Vizier of the Karabakh Khnanate during that time, after a defeat of Persian Empire in the battle near the Tugh village, Fath Ali Shah Qajar, the Shah of Persian Empire, offered Ibrahimkhalil Khan to create an alliance against Tsarist Empire. Tsarist Empire envoys also visited the Karabakh Khanate very often during that period. After the long discussion of the existing political situation Ibrahimkhalil Khan decided that the conquest of Tsarist Empire is unavoidable. In fact, he was afraid that the tragic event that happened during the occupation of the Ganja Khanate by Tsarist Empire might be reiterated in the Karabakh Khanate. Meanwhile, he was also concerned at the treachery of Karabakh Khanate’s Christian meliks, who were incited by the Armenian military officers that were serving in the Tsarist Empire’s army. At a time when the Tsarist Empire was preparing for a military attack on the Karabakh Khanate, Ibrahimkhalil Khan made his decision and sent a request for a meeting with General Sisianov, the commander-in-chief of the Tsarist Empire’s army in the Caucasus. As a result of this meeting between General Sisianov and Ibrahimkhalil Khan, the Treaty of Kurekchay, consisting of 11 articles, was signed between the Tsarist Empire and the Karabakh Khanate on May 14, 1805. As a result of this treaty, the Karabakh Khanate lost its independence and came under the tutelage of the Tsarist Empire. Based on the Treaty, a group of 500 Tsarist Empire soldiers under the command of officer Lisianovich was stationed in the city of Shusha. They were given the right to intervene in all issues within the Karabakh Khanate. Meanwhile, the government of the Tsarist Empire gave Ibrahimkhalil Khan the rank of Lieutenant General, and his sons, Muhammad Hasan Agha and Mehdigulu Bey, the ranks of General Officer of the Tsarist Empire.
 Bakıxanov, Abbasqulu Ağa, Gülüstani İrəm (Bakı, 1951), pp. 193. See also: Əsədov, Firudin and Sevil Kərimova, Çarizmi Azərbaycana gətirənlər (Bakı: Gənclik, 1993), p. 56. See also: Bala, Mirze, “Gence”, İslam Ansiklopedisi, Vol. 4, (İstanbul, 1988), pp. 764-765.
 Uçarol, Rifat, Siyasi Tarih (1789-1994) (İstanbul: Filiz yayınevi, 1995), pp. 84-85.
 Azərbaycan Tarixi, Vol. 4, (2007), pp. 20-21.
 Qarabaği, Mirzə Camal Cavanşir, “Qarabağ tarixi”, in Akif Fərzəliyev (ed.), Qarabağnamələr (Bakı: Yazıçı, 1989), pp. 133-134.
 Əsədov and Kərimova, Çarizmi Azərbaycana gətirənlər, p. 45.
 Bakıxanov, Gülüstani İrəm, p. 194.
 Bakıxanov, Gülüstani İrəm, p. 194. See also: Qaradaği, Həsənəli, “Qarabağ vilayətinin qədim və cədid keyfiyyəti və övzaları”, in Nazim Axundov (ed.), Qarabağnamələr (Bakı: Yazıcı, 1991), p. 135.