According to medieval Armenian sources, the settlement was first mentioned as Vararakn (Վարարակն, meaning "rapid spring" in Armenian), a name that remained in use until 1847, when it was renamed Khankendi. Azerbaijani sources generally say that the settlement was founded in the late eighteenth century as a private residence for khans of the Karabakh Khanate, and was thus called Khankendi (Turkic for "the khan's village"). The settlement was initially called Khanin Kendi (Xanın kəndi), but then was shortened to Khankendi. After the Russian Empire gained the territory of the Karabakh Khanate through the Russo-Persian War of 1804–1813, the name Khankendi was charted on Russian maps.
In 1923 Khankendi was renamed Stepanakert by the Soviet government to honor Stepan Shahumyan, ethnic Armenian leader of the 26 Baku Commissars, and, after the Shusha pogrom had resulted in major destruction at Shusha, the former regional capital, Stepanakert was made the capital of the Nagorno-Karabakh Autonomous Oblast (NKAO). In time, Stepanakert grew to become the region's most important city (a status it received in 1940). Its population rose from 10,459 in 1939 to 33,000 in 1978.
In 1926, municipal authorities adopted a new city layout designed by the prominent Armenian architect Alexander Tamanian; two additional designs for expansion were approved later on in the 1930s and 1960s, both of which retained Tamanian's initial plan. Several schools and two "polyclinics" were established, and an Armenian drama theater was founded in 1932 and named after Maxim Gorky. Stepanakert served as Nagorno-Karabakh's main economic hub, and by the mid-1980s there were nineteen production facilities in the city.