Ibrahim KhalilkhanJavanshir was the Azeri Turkic khan of Karabakh from the Javanshir family, who succeeded his father Panah-Ali khan Javanshir as the ruler of Karabakh khanate. In the 1780s, Ibrahim Khalil Khan emerged as one of the most powerful rulers in the eastern Caucasus. He aspired to bring most of the Muslim-ruled territory from the Caucasus mountains as far south as Tabriz under his sway, but eventually he had to curb his efforts in the face of the rising Qajar power in Iran. He was then allied with the Georgian kingErekle II of Kartli-Kakheti and the two interfered in the affairs of the Erivan khanate and made the Ganja khanate their puppet. The alliance waned after Erekle accepted the Russian protectorate in the treaty of Georgievsk in 1783. Ibrahim maintained contact with the Russian authorities, but did not sign any formal treaty. In 1795 the ruler of Iran, Agha Mohammad Khan Qajar, attacked the region to bring it again within the Iranian empire. The khans of Ganja, Nakhjavan, and Erevan submitted, but Ibrahim Khan did not. He was defeated in battle and retreated to the fortress of Shusha. After a prolonged siege, Agha Mohammad Khan Qajar failed to take the fortress and left the region. In a verbal truce, Ibrahim Khan acknowledged Qajar supremacy and was permitted to continue to rule as Khan of Karabakh. In 1796, following Agha Mohammad Khan's return to mainland Persia, Catherine the Great ordered her army to conquer the Caucasus. Ibrahim began negotiating with the Russian commanders and agreed to cooperate with them in exchange for maintaining his rule in Karabakh. Soon after Catherine the Great died, her successor, Paul, abandoned her plans for the region and recalled the Russian troops. In 1797, Aga Mohammad Khan, angered by the betrayal of Ibrahim Khalil Khan and other khans in the Caucasus, attacked and captured Shusha. Agha Mohammad Khan was assassinated in Shusha five days after its capture. Ibrahim, who had fled to his in-laws in Dagestan, then returned to Shusha and gave Aga Mohammad Khan an honourable burial. In order to retain his position and ensure peaceful relations with the shah, he gave one of his daughters to Agha Mohammad Khan's successor to the throne, Fat′h Ali Shah Qajar. During the Russo-Persian War, General Tsitsianov promised that Russia would recognize Ibrahim Khan as khan and agreed that Ibrahim's elder son would succeed his father, and thus an agreement was signed between Russia and Ibrahim Khan on May 14, 1805. Tsitsianov then occupied Shusha and left a Russian garrison stationed there. Tsitsianov's death on 20 February 1806 and the breakup of the Russian offensive persuaded Ibrahim Khalil Khan, in the summer of 1806, to repudiate his allegiance to the Russians, and resubmit himself to the shah; he then asked the shah for aid in ousting the Russian garrison. As the Persian army approached Shusha, Ibrahim Khan left the fortress and camped outside. On 2 June 1806, the Russians, instigated by Armenians and fearful of their own vulnerability, attacked the camp and killed Ibrahim Khan, one of his wives, a daughter, and his youngest son. To gain support from the local Muslims, the Russians appointed a son of Ibrahim Khalil, Mehdigulu Khan Javanshir, as khan of Karabakh.