The city has a rich heritage and has provided the backdrop to major political events throughout much of its two millennia of existence. For centuries, Shamaxa (Shemakha) was one of (northern) Azerbaijan's most prominent cities, an important cultural and trading centre and the royal seat of the Shirvanshahs (9th to 18th centuries).
In its history eleven major earthquakes have rocked Shamakhi, but through multiple reconstructions it maintained its role as the economic and administrative capital of Shirvan and one of the key towns on the Silk Road. The only building to have survived eight of the eleven earthquakes is the landmark Juma Mosque, built in the 10th century.
Apart from that, earthquakes, fire and invasions have left virtually nothing visible to remind the visitor of Shemakha's past importance. In the Soviet era the surrounding hills produced famous wines and cognacs but that industry was decimated by Gorbachev's anti-alcohol campaign and has never fully recovered. These days the town is best seen as a staging point for reaching Pirqulu rather than as a destination in itself.
The city's estimated population as of 2010 was 31,704. It is famous for its traditional dancers, the Shamakhi Dancers.
Shamakhi was first mentioned as Kamachia by the ancient Greco-Roman Egyptian geographer Claudius Ptolemaeus in the 1st to 2nd century.
Shamakhi was an important town during the Middle Ages and served as a capital of the Shirvanshah state in 8-15 century and the capital of the independent Shirvan Khanate, which was also known as the khanate of Shemakha. The Catholic friar, missionary and explorer William of Ruysbroeck passed through it on his return journey from the Mongol Great Khan's court.
In the middle of the 16th century it was the seat of an English commercial factory, under the traveler Anthony Jenkinson, who was afterward the envoy extraordinary of the Persian Shah to Tsar Ivan IV the Terrible of Russia.
Until the devastating earthquake of 1859, Shamakhi was the capital of the Shamakhi Governorate of the Russian Empire. From 1859, when the capital of the province was transferred to Baku, the importance of the city declined.