the fortress and he was forced to call a siege off. He ordered to devastate outskirts of the country. After their departure Karabakh burst into starvation. In 1797, Agha Mohammad Khan invaded Karabakh again. Until then, situation of the Karabakh Khanate was extremely difficult: starvation and plague were rife and rampant in the country and many of the citizens of Karabakh were forced to move to other khanates looking for bread. Withstanding of the second siege was impossible and Ibrahim Khalil Khan left the city and escaped to Dagestan with his family. But after conquering Shusha, Agha Mohammad Khan was murdered by his servants and losing its leader the Iranian army left Karabakh. Ibrahim Khalil Khan came back to Shusha and ruled there for several years as a fully independent ruler. He tried to support good relations with Fathali Shah - a new ruler of Iran, nephew of Agha Mohammad Khan. But this peace was not durable. Ceding to Russia Not severing relations with the khan, the shah attempted to bring its garrison to Shusha. In May 1805, Ibrahim Khalil Khan renewed discussions with Russia and moved to Russian citizenship. An agreement was later reached, by which Ibrahim Khalil Khan was allowed to continue to rule the khanate, and his son Mehdiqoli khan Javanshir would be confirmed as his successor. Ibrahim Khalil Khan was obliged to pay an annual tribute of 8,000 chevrons, and allowed the Russian garrison to enter Shusha. He hoped that hereby he will be able to save his government from capture of neighbor states, but he precipitated its end. In the spring of 1806, when the Iranian army consisting of 20 thousand soldiers arrived at Shusha, lieutenant-colonel Lisanevich, commander of the Russian garrison, ordered 80-years-old Ibrahim Khalil Khan for suspicion and betrayal and annihilated all his family (including of his wives and a lot of little children). Russian Government announced Mehdigulu khan Vafa, the son of Mehdiqoli khan Javanshir, as the new khan, but he didn't forgive the Russians and was a secret ally of Iran during the time of his reign. Meanwhile, in 1813, at the end of the Russo-Iranian war of 1804–1813, the first of the two major Russo-Iranian treaties of the 19th century—known as the Treaty of Golestan—was signed in the Golestan fortress of Karabakh. Per the treaty, the conversion of the Karabakh Khanate to Russia was recognized and Qajar Iran was forced