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 of Shamakhi, built in the 10th century.
Shamakhi was first mentioned as Kamachia by the ancient Greco-Roman Egyptian geographer Claudius Ptolemaeus in the 1st to 2nd century CE.
Shamakhi was an important town during the Middle Ages and served as a capital of the Shirvanshah realm from the 8th to 15th centuries.
The Catholic friar, missionary and explorer William of Ruysbroeck passed through it on his return journey from the Mongol Great Khan's court. In 1476 Venetian diplomat Giosafat Barbaro, while describing the city, stated: "This [Sammachi] is a good city; it has from four to five thousand houses, it produces silk, cotton as well as other things according to its tradition; it is situated in greater Armenia (Armenia grande) and the majority of its residents are Armenians".
In 1500-1501, it was taken by the Safavid Iranians. Following the conquest of the area by the first Safavid ruler Ismail I, he allowed the descendants of Farrukh Yassar to rule Shamakhi and the rest of Shirvan under Safavid suzerainty. This lasted until 1538, when his son and successor, king Tahmasp I (r. 1524-1576), turned the territory into a full Safavid province and appointed its first Safavid governor. From then on, Shamakhi functioned as the capital of the Shirvan province. In 1562 Englishman Anthony Jenkinson described the city in the following terms: "This city is five days' walk on camels from the sea, now it has fallen a lot; it is predominantly populated by Armenians..." Adam Olearius, who visited Shamakhi in 1637, wrote: "Its inhabitants are in part Armenians and Georgians, who have their particular language; they would not understand each other if they did not use Turkish, which is common to all and very familiar, not only in Shirvan, but also everywhere in Persia". The Ottoman traveller Evliya Celebi visited the town in 1647 and described it as having
In 1721, the Lezgins of the Safavid provinces of Shirvan and Dagestan, aided by the (rest of the) Sunni inhabitants of the area, sacked the city. They massacred thousands of its Shia inhabitants, apart from looting the city and robbing the property of its Christian inhabitants and foreign nationals, the latter which were mostly the city's many Russian merchants.
The Russian forces first entered Shirvan in 1723, as they invaded the Safavid Iranian territories in the North Caucasus and Transcaucasia during the Russo-Persian War (1722-1723), using the attack on their subjects in Shamakhi shortly before by the rebellious Lezgins as one of the pretexts. They however soon retired from the city, leaving it to Ottomans who possessed it in 1723-35, until Nader Shahs rise. In 1742 Shamakhi was taken and destroyed by Nader Shah of Persia reincorporating it back to Iran, and, who, to punish the inhabitants for their Sunnite creed, built a new town under the same name about 26 kilometres (16 mi) to the west, at the foot of the main chain of the Caucasus Mountains. The new Shamakhi was at different times a residence of the Shirvan Khanate, ruled by the from Iran semi-independent khans, but it was finally abandoned, and the old town rebuilt. In the mid-1700s, the population of Shamakhi was about 60,000, most of whom were Armenians. The Shirvan Khanate was finally annexed by Russia in 1805 during the Russo-Persian War (1804-1813) and Qajar Iran was forced to irrevocably cede the sovereignty over the town after centuries in the early modern era, to Russia, conform the Treaty of Gulistan of 1813.
The British Penny Cyclopaedia stated in 1833 that "The bulk of the population of Shirvan consists of the Tahtar, or, to speak more correctly, Turkish race, with some admixture of Arabs and Persians. . . . Besides the Mohammedans, who form the mass of the population, there are many Armenians, some Jews, and a few Gipsies. According to the official returns of 1831, the number of males belonging to the Mohammedan population was 62,934; Armenians, 6,375; Jews, 332; total males 69,641. The prevalent language of Shirvan is what is there called Toorkee or Turkish, which is also used in Azerbijan". The same source also states that according to the official returns of 1832, the city of Shamakhi was inhabited by only 2,233 families, as a result of devastation from the sack of the city "in the most barbarous manner by the highlanders of Daghestan" in 1717. The Encyclopædia Britannica stated that in 1873 the city had 25,087 inhabitants, "of which 18,680 were Tartars and Shachsevans, 5,177 were Armenians, and 1,230 Russians". Silk production continued to be the main output, with 130 silk-winding establishments, owned mostly by Armenians, although the industry had considerably declined since 1864.
Shamakhi was the capital of the Shamakhi Governorate of the Russian Empire until the devastating earthquake of 1859, when the capital of the province was transferred to Baku. The importance of the city declined sharply afterwards. According to the Brockhaus and Efron Encyclopedic Dictionary (vol. 77, p. 460, published in 1903), Shamakhi had 20,008 inhabitants (10,450 males and 9,558 females), of which 3% were Russians, 18% were Armenians, and 79% "Azerbaijani Tatars". With regard to religion, 79% of the population was Muslim, of which 22% was Sunni and the rest Shiite; the remaining 21% was "Armeno-Gregorian" (members of the Armenian Apostolic Church) and "Pravoslav" (Orthodox).
The city is located in the most seismic area of the Caucasus and was hit by powerful earthquakes in 1191 and 1859, which was so destructive that the capital of Shirvan was transferred to Baku twice. In 1872, the earthquake triggered emigration to Baku, where oil production had started in industrial proportions.
The 1667 earthquake is considered to have been the worst with a death toll of 80,000, with one-third of the city collapsed, according to the Persian merchants' reports. The last catastrophic earthquake was recorded in 1902, which destroyed the 10th-century Juma Mosque. Shamakhi is near the boundary of three plates.
The majority of the population is Azerbaijanis, while Russians, Lezgians and Tats constitute other minorities. They speak Azerbaijani language, Russian language, Lezgian language and Tati language respectively.
Juma Mosque of Shamakhi is the biggest religious premise in the city. Through its history the mosque was demolished and destroyed few times, but each time it was rebuilt, most recently in 2009.
The notable businesses headquartered in Shamakhi include automobile factory AzSamand.
In the 19th century, the town was famous due Shamakhi dancers, the principal dancers of the entertainment groups, similarly to tawaifs. The city is home to Shirvan Domes, a 15th-century mausoleum and graveyard located at the foot of Gulistan Fortress.
The music scene in Shamakhi can be traced back to ancient times and villages of Baku, generally revered as the fountainhead of mugham in the Azerbaijan.
Shamakhi Humanitas College.Şamaxı Humanitar Kolleci
Shamakhi is twinned with the following cities:
Some of the city's many prestigious residents include: philosopher Seyid Yahya Bakuvi, poets Seyid Azim Shirvani, Khaqani and Mirza Alakbar Sabir, mugham singers Alim Qasimov and Farghana Qasimova, actors Aghasadyg Garaybeyli and Abbas Mirza Sharifzadeh, architect Gasim bey Hajibababeyov,Armenian playwright and novelist Alexander Shirvanzade . and others.