Shusha was founded in 1750-1752 by Panah-Ali khan Javanshir (r. 1748-1763), the founder and the first ruler of the Karabakh Kanate (Qarabag xanligi - in Azerbaijani). The first capital of the Karabakh khanate was castle of Bayat, built in 1748 in the district of Kebirli. However, soon afterwards Panah Ali khan realized that in order to secure himself and his newly established khanate from external threats, he needed to build a new more reliable castle. Shusha was turned into the capital of the Karabakh khanate.