Sack of Shamakhi

The Sack of Shamakhi took place on 18 August 1721, when rebellious Sunni Lezgins, within the declining Safavid Empire, attacked the capital of Shirvan province, Shamakhi (in present-day Azerbaijan Republic). The initially successful counter-campaign was abandoned by the central government at a critical moment and with the threat then left unchecked, Shamakhi was taken by 15,000 Lezgin tribesmen, its Shia population massacred, and the city ransacked.
The deaths of Russian merchants within Shamakhi were subsequently used as a "casus belli" for the Russo-Persian War of 1722–1723, leading to the cessation of trade between Iran and Russia and the designation of Astrakhan as the new terminus on the Volga trade route.
Background.
By the first decade of the 18th century, the once-prosperous Safavid realm was in a state of heavy decline, with insurrections in numerous parts of its domains. The king, Sultan Husayn, was a weak ruler, and although personally inclined to be more humane, flexible, and relaxed than his chief mullah, he went along with the recommendations of his advisers regarding important state decisions. He reigned as a "stationary monarch", preferring, apart from the occasional hunting party, to be inside or near the capital of Isfahan at all times, invisible to all "but the most intimate of courtiers". Having seen not much more of the world than the harem walls, he had quickly fallen under the spell of the leading ulama, most notably Mohammad-Baqer Majlesi. Majlesi, who had already gained considerable political power during the reign of Sultan Husayn's predecessor SuleimanI ( 1666–1694), instigated the persecutions directed towards Safavid Iran's Sunni and Sufi inhabitants, as well as its non-Muslim religious minorities, namely Christians, Jews, and Zoroastrians. Though the Christians, mainly represented by the Armenians, suffered less than other groups, they were also targeted from time to time. According to historian Roger Savory, even though Sultan Husayn did not show personal hostility towards Christians, he was persuaded by the clergy (Majlisi in particular), who had great influence over him, to issue "unjust and intolerant decrees". The tense religious atmosphere in the late Safavid era would prove to be a significant factor in the revolts by Sunni adherents from various places within the empire. As the historian Michael Axworthy notes: "The clearest example was the revolt in Shirvan, where Sunni religious men had been killed, religious books destroyed and Sunni mosques turned into stables".
The Sunni population in the northwestern domains of the Safavids, comprising Shirvan and Daghestan, felt the burden of the Shia persecution during Sultan Husayn's reign. 1718 saw an intensification of the Lezgin incursions into Shirvan, rumoured, according to historian Rudi Matthee, to have been incited by then grand vizier Fath-Ali Khan Daghestani (1716–1720). Russia's ambassador to Safavid Iran, Artemy Volynsky, who was in Shamakhi in 1718, reported that, because local officials considered the grand vizier "an infidel", they considered his orders invalid and even questioned the king's authority. Florio Beneveni, an Italian in the Russian diplomatic service, insisted that Shamakhi's inhabitants were ready to revolt against the government for "extorting large sums of money from them". The marauding raids, incursions, and pillages nevertheless carried on; in April of the same year, the Lezgins took the village of AkTashi (located near Nizovoi), but not before abducting a number of its inhabitants and plundering a caravan of 40people on the road to Shamakhi. After these events, numerous additional reports in relation to the rebels are reported.
Attack and sack.
By early May 1718, some 17,000 Lezgin tribesmen had reached a distance of from Shamakhi, occupying themselves with looting settlements in Shamakhi's surrounding areas. In 1719, the Iranian government decided to send the "sepahsalar" Hosaynqoli Khan (VakhtangVI of Kartli) to Georgia with the task of confronting the Lezgin rebellion. Assisted by the ruler of neighboring Kakheti, as well as the "beglarbeg" of Shirvan, Hosaynqoli Khan moved to Daghestan and made significant progress in putting a halt to the Lezgins. However, in the winter of 1721, at a crucial moment in the campaign, he was recalled. The order, which came after the fall of grand vizier Fath-Ali Khan Daghestani, was made at the instigation of the eunuch faction within the royal court, who had persuaded the shah that a successful end of the campaign would do the Safavid realm more harm than good. In their view, it would enable Vakhtang, the Safavid "vali", to form an alliance with Russia with an eye to conquering Iran. Around the same time, in August 1721, Sultan Husayn ordered Daud Beg, a rebel mountaineer chieftain of the Lezgins and a Sunni cleric, to be released from prison in the Safavid city of Derbent. The government's decision to release him came shortly after the Afghan attack on Safavid Iran from within its far easternmost domains. Sultan Husayn and the government were hoping that Daud Beg and his Daghestani allies would assist in countering the revolt on the eastern front, but Daud instead put himself at the head of a tribal coalition, and then launched a campaign against both the Safavid government forces and the empire's Shia population, eventually marching upon the provincial capital of Shamakhi. 
Shortly before the siege, the Sunnis of Shirvan province appealed for help from the Ottomans, their co-religionists and the arch-rivals of the Safavids. The rebel "coalition" consisting of some 15,000 tribesmen, headed by Daud Beg and assisted by Surkhay Khan of the Ghazikumukh, moved towards Shamakhi which was subsequently put under siege. Eventually, the Sunni inhabitants of Shamakhi opened one of the gates of the city to the besiegers; Shamakhi was taken on 18August 1721, upon which thousands of Shia residents were massacred, while Christians and foreigners were merely robbed. Several Russian merchants were killed as well. The stores of the many Russian merchants were looted, resulting in grave economic losses for them. Amongst the merchants was Matvei Evreinov, "reputedly the wealthiest merchant in Russia", who suffered huge losses. The Shia Safavid governor of the city, his nephew, and the rest of his relatives were "cut to pieces by the mob, and their bodies thrown to the dogs". After the province was completely overrun by the rebels, Daud Beg appealed to the Russians for protection, declaring his loyalty to the Tsar. Upon being rebuffed, he appealed to the Ottomans, this time successfully; he was then designated by the Sultan as Ottoman governor of Shirvan.
Aftermath.
Artemy Volynsky reported to then Tsar Peter the Great (1682–1725) on the considerable harm done to the Russian merchants and their livelihoods. The report stipulated that the 1721 event was a clear violation of the 1717 Russo–Iranian trade treaty, by which the latter had guaranteed to ensure the protection of Russian nationals within the Safavid domains. With the Safavid realm in chaos, and the Safavid ruler unable to fulfill the provisions of the treaty, Volynsky urged Peter to take advantage of the situation and to invade Iran on the pretext of restoring order as an ally of the Safavid king. Indeed, Russia shortly afterward used the attack on its merchants in Shamakhi as a pretext to launch the Russo-Persian War of 1722–1723. The episode brought trade between Iran and Russia to a standstill, and made the city of Astrakhan the terminus for the Volga trade route.