Bakikhanov and Mirza Yusuf Nersesov, attest to the foundation of the town in 1750–1752 (according to other sources, 1756–1757) by Panah Ali Khan (), the founder and the first ruler of the Karabakh Khanate (1748–1822), which comprised both Lowland and Highland Karabakh. The mid-18th century foundation is supported by the second edition of the Encyclopaedia of Islam, and the Brockhaus and Efron Encyclopedic Dictionary. According to Mirza Jamal Javanshir, the author of the Persian-language text History of Karabakh, one of the most significant chronicles on the history of Karabakh in 18th-19th centuries, the Karabakh nobility assembled to discuss the danger of invasion from Iran and told Panah Ali Khan, "We must build among the impassable mountains such an inviolable and inaccessible fort, so that no strong enemy could take it." Melik Shahnazar of Varanda, who was the first of the Armenian meliks (dukes) to accept the suzerainty of Panah Ali Khan and who would remain his loyal supporter, suggested a location for the new fortress. Thus, Panahabad-Shusha was founded. According to Mirza Jamal Javanshir, before Panah Ali Khan constructed the fortress there were no buildings there and it was used as cropland and pasture by the people of the nearby village of Shoshi. Panah khan resettled to Shusha the population of Shahbulag and some nearby villages and built strong fortifications. Another account is presented by Raffi (1835–1888), an Armenian novelist and historian, in his work The Princedoms of Khamsa, which asserts that the place where Shushi was built was desolate and uninhabited before Panah Ali Khan's arrival. He states, "[Panah-Ali Khan and Melik-Shahnazar of Varanda] soon completed the construction (1762) [of the fortress] and moved the Armenian population of the nearby village of Shosh (Շոշ), called also Shoshi, or Shushi into the fortress.″ Conflict with the Qajars Although Panah Ali Khan had been in conflict with Nader Shah, the new ruler of Persia, Adil Shah, issued a firman (decree) recognizing Panah Ali as the Khan of Karabakh. Less than a year after Shusha was founded, the Karabakh Khanate was attacked by Mohammad Hassan Khan Qajar, one of the major claimants to the Iranian throne. During the Safavid Empire Karabakh was for almost two centuries ruled by Ziyad-oglu family of the clan of Qajars (of Turkic origin), and therefore, Muhammed Hassan Khan considered Karabakh his hereditary estate. Muhammed Hassan Khan besieged Shusha (Panahabad at that time) but soon had to retreat