On orders from Panah Ali-khan, the ancient castles of Asgaran and Shah-Bulag, where the centre of the khanate was moved, were restored. In 1751, the construction of another castle began on a high steep mountain. The new centre of the Karabakh khanate was surrounded by rocks and high walls and was strongly fortified. initially, the castle bore the name of its founder – Panahabad, but then it adopted its previous name Shusha or Shusha Galasi and quickly turned into the economic centre of Karabakh, becoming one of the major cities of trade and craftsmanship in Azerbaijan. Caravan routes lied through Shusha, connecting the South Caucasus to Iran. Relying on the impregnable capital of Panahabad-Shusha, the Karabakh khan started to unite neighbouring Azerbaijani lands. As a result of successful military and political actions by Panah Ali-khan, his supremacy was recognised by the khans of Iravan, Nakhchivan, Ganja, Garadag and Ardabil. The territory of the Karabakh khanate expanded significantly.
Less than one year after the construction of the new castle, the Karabakh khanate was attacked by Muhammad Hasan-khan Gajar, one of the main contenders for the shah’s throne in Iran. Deciding not to besiege the strong castle, Gajar and his troops stayed for a month far away from Shusha in the Khatunarkhi area, for “he could not [even] approach the outskirts of the castle with such a [big] army”[ref]Mirza Jamal Javanshir, ibid., p. 73[/ref]. Having met with resistance and received news from Iran about the start of a new fight for the shah’s throne, Gajar left Karabakh. His retreat was so hasty that he even left his cannons behind[ref]Mirza Adigozal-bey, ibid., p. 64[/ref].
Soon, Panah Ali-khan encountered a new threat from the south. in 1759, the Karabakh khanate was invaded by the 30,000-strong army of one of Nadir-shah’s famous military commanders – the ruler of Urmiya, Fatali-khan Afshar, who managed to subjugate all the southern regions of Azerbaijan. He devastated a number of areas in Karabakh. as soon as the enemy troops set foot in Karabakh soil, some meliks betrayed their suzerain and defected to Fatali-khan: “The meliks of Chilaburd (Jeraberd) and Talish, who were covertly hostile to Panah khan, joined Fatali khan. They stayed near the castle for six months…”[ref]Mirza Jamal Javanshir, ibid., p. 74[/ref]. in a decisive battle, Fatali-khan’s troops suffered a major defeat.”
The military failures and the onset of the winter forced Fatali-khan to sign a peace treaty. The meeting between the two prominent rulers took place on Aga Bridge near Shusha[ref]Mirza Adigozal-bey, ibid., p.70[/ref]. On the pretext of exchanging prisoners and marrying his daughter to the elder son of the Karabakh khan, Ibrahim Khalil-aga, Fatali-khan managed to invite the heir to the khan’s throne to his camp. After that, declaring Panah Ali-khan his vassal, Fatali-khan took his son hostage[ref]Mirza Jamal Javanshir, ibid., pp.74–75[/ref].
Soon, power in Iran was seized by Karim-khan Zand, who launched an offensive on Urmiya’s Fatali-khan and won over Panah Ali-khan of says: “Panah Ali-khan, who always sought an opportunity to destroy Fatali-khan, immediately created an enormous army and large cavalry and went to help Karim-khan”[ref]Mirza Adigozal-bey, ibid., p. 72[/ref]. The allies managed to gain a victory.
After that, Karim-khan freed Ibrahim Khalil-aga from captivity and sent him to Karabakh as a khan, providing him with a special firman. As for his former ally, Karim-khan treacherously kept him as a hostage. Panah Ali-khan died in Shiraz in 1763. His body, according to his will, was buried in agdam in a place called imaret.
Thus, the Karabakh khanate emerged and strengthened in a fierce fight. In the middle of the 18th century, it occupied a vast territory.
The khanate included the whole of Karabakh. The melikdoms, as well as Zangazur, Hajisamli and Chalbair were under its jurisdiction. Panah Ali-khan sought to expand the khanate at the expense of neighbouring feudal possessions: he engaged in a lengthy fight for Garadag, Ganja and Nakhchivan. The Karabakh khanate always remained independent. “He [Panah-khan] did not serve anyone and did not put his neck under the yoke of obedience to anyone…”[ref]I. P. Petrushevskiy. Essays on the history of feudal relations in Azerbaijan and Armenia in the 16th-19th centuries. Leningrad, 1949, p. 137[/ref].