Mostafa Khan of Shirvan (; ; 1768 – 17 September 1844) was the last Khan of Shirvan under Russian suzerainty. He ruled the Shirvan Khanate from 1792 until his deposition by General Yermolov in August 1820. Known to the Russian army as "the bearded serpent of Shirvan,"Juan Van Halen, Narrative of Don Juan Van Halen's Imprisonment in the Dungeons of the Inquisition at Madrid, and His Escape in 1817 and 1818; to Which Are Added His Journey to Russia..., vol. II (London: Henry Colburn, 1827), p. 351. he was simultaneously one of Russia's most important vassals and, in Russian commanders' private assessments, one of the most difficult to control. His khanate, the largest in the Caucasus by population, submitted formally to Russia in 1805 but was never fully integrated into the imperial administrative system during his lifetime.

Loyal to Russia from 1803, he was deposed on accusations that every formal Russian investigation found unproven. He kept his stated promise not to take up arms against Russia — until six years of Persian exile left him no alternative. He entered Russian allegiance a second time in 1831 and settled in Karabakh, where he died in 1844. He never returned to Shirvan.

Background and early life Mostafa Khan was born in Shamakhi in 1768, the son of Aghasi Khan of the House of Sarkar, a branch of the Khanchobani tribe, and of Bibikhanim, daughter of Safarali Sultan. His father Aghasi Khan was executed on the orders of Fath Ali Khan of Quba in 1788. Following his father's death, the young Mostafa fled together with his cousins Askar and Qasim (sons of his uncle Muhammad Said Khan) to seek protection from neighbouring rulers.

According to the Russian-Armenian officer Averian Serebrov, who was dispatched to the region in 1796, the young princes were briefly arrested by Shabaddin Sultan of the Arash Sultanate acting on instructions connected to Fath Ali Khan, but a loyalist of the House of Sarkar spread a rumour that disrupted the escort and they were released, making their way first to the Avar Khanate and then to Karabakh, where they enjoyed the protection of Ibrahim Khalil Khan.Averian Serebrov, Istoriko-etnograficheskoe opisanie Dagestana (1796). Available at drevlit.ru. The historian Abbasgulu Bakikhanov records that both the Karabakh and Shaki khans later came to the princes' aid, besieging New Shamakhi for a prolonged period, though the siege ultimately failed.

Struggle for Shirvan Fath Ali Khan of Quba died in April 1789 (New Style), removing the principal obstacle to the Sarkar family's return. The sequence of rule that followed was contested: according to Serebrov, upon hearing of Fath Ali Khan's death, Askar Khan arrived with armies from Karabakh and seized Shamakhi, executing a rival claimant installed by Muhammad Hasan Khan of Shaki. Bakikhanov's account differs, stating that Askar Khan was installed as khan among the nomadic clans (ilat) while Mostafa withdrew to Alvand, his father's former base.

Askar Khan's rule proved brief and contested. Bakikhanov records that only six months into Askar Khan's tenure, the Shirvan nobility grew disillusioned with his passivity and shifted their support to his brother Qasim Khan. Qasim Khan — Mostafa's cousin on the paternal side — then administered Shirvan for a period.

Rule of Shirvan

Early reign In 1792, the Shirvan nobility led by Yüzbashi Bey Hovzi and Omar Sädäri invited Mostafa to come from Alvand and raise the banner of government in Shamakhi. Mostafa Khan established himself as Khan of Shirvan, displacing Qasim Khan which coincided with the devastating invasion of Agha Mohammad Khan Qajar. Mostafa was among the rulers who didn't accept Agha Mohammad's claim to shahdom who in turn sent 12,000-strong army under Mostafa khan Davalu-Qajar, a Qajar commander with task of conquering Shirvan. Besieging Mostafa in Fit-Dagh, he was accused by the local elders of looting and oppression. Which caused his recall by the shah. However, Mostafa's loyal Khanchobani tribesmen ambushed and killed him on the road in 1793. Enraged shah sent his half-brother Ali-Qoli Khan Qajar as his replacement to Shirvan. Unable to withstand the pressure, Mostafa submitted to Agha Mohammad.

Mostafa Khan's earliest documented approach to Russia dates to 1800. Facing a threatened Persian military expedition — ordered by Fath-Ali Shah (referred to in Russian sources as Baba Khan) in retaliation for Mostafa Khan's interception of a bride convoy destined for the Shah — he sent envoys seeking imperial protection. The background to this episode was that Ibrahim Khan of Karabakh had promised his daughter Agha Baji both to Mostafa Khan and to Fath-Ali Shah; when Ibrahim Khan's daughter was dispatched to Tehran, Mostafa Khan intercepted the convoy on the road with armed men. This act of defiance, combined with his earlier refusal to acknowledge Persian sovereignty — he had dismissed the Shah's envoy with the reply: "Tell your master that the Shah's pen is also mine" — made a Persian punitive expedition probable.

In July 1800, General Knorring reported to St Petersburg that "the Shirvan Mostafa Khan and the Sheki Mahomed-Hasan Khan" wished to be under Russian imperial protection. Tsar Paul I's rescript of 24 August 1800 [O.S. 12 August] consented to this request.

Russo-Persian War (1804–1813) Formal subjection to Russia came in 1803, under General Pavel Tsitsianov, however, Mostafa was unwilling to come to sign terms in person. As result, Tsitsianov took a punitive expedition to Shamakhi, in the meantime, he wrote a letter to Ibrahim Khan and asked him to send a 1000-strong army under his son Mehdiqoli and Dmitry Lisanevich. Mostafa Khan ambushed their army with 80 horsemen who managed to wound two cossacks on 23 December 1806 but nevertheless defeated. A treaty was concluded on 6 January 1806 [O.S. 25 December 1805] at the foot of Fit-Dagh. The negotiation was conducted on Mostafa Khan's terms: Russian troops were required to halt at a distance from the city and the meeting took place at a specially prepared venue outside the walls. Mostafa Khan had hoped Russia would recognise a Shirvan enlarged to the boundaries of the medieval Shirvanshahs; Tsitsianov made clear this was not on offer and reportedly threatened to replace him with a more compliant member of his family if he refused. Under the treaty as concluded, Mostafa Khan accepted Russian suzerainty and an annual tribute of 8,000 chervonets; in return, Russia recognised his possession of Salyan under Article 5 of the agreement. He was confirmed in the rank of Lieutenant-General in the Russian imperial service. His formal declaration read:

When Tsitsianov was killed at Baku in February 1806, Mostafa Khan was attacked by a contingent sent by Abbas Mirza following month, soon arrived with Hossein Khan Sardar. They took Shamakhi on August 24 and managed to under Esma'il Khan Damghani and Amanullah Khan Afshar to forcibly move 6,000 nomadic families (ilat) from Shirvan and resettled them in Qarajadagh and the Mughan plain, which were under firmer Persian control. He subsequently re-established relations with Russia and asked for reinforcements from Russian army, effectively foreclosed any return to the Persian fold.

Leaving Fit Dagh, Mostafa Khan invaded Salyan which was under occupation of Mir Baqer, brother of Mir-Mostafa Khan of Talysh. Capturing 300-strong Talysh army, Mostafa Khan didn't hesitate to boast about it. "The Persian blood he shed" in 1806 was a fact subsequently cited by Russian commanders as the most reliable guarantee of his loyalty: he had made enemies he could not afford to change sides to.

Throughout the period 1809–1816, Mostafa Khan repeatedly refused to send the cavalry contingents Russia demanded, accumulated large tribute arrears, and fortified Fit-Dagh as a refuge. He transformed the mountain plateau into a fully functioning city in 1810, establishing it as khanate's capital, resettling 1,000 families and establishing arms factories and specialized artisan districts. He granted these residents total tax immunity to ensure their loyalty and the city's self-sufficiency.

These behaviours, while consistent with the assertive autonomy he had always maintained, were increasingly read by Russian commanders as signs of insubordination. Several commanders conducted formal investigations; all found the charges of treason unproven. General Tormasov issued a comprehensive exoneration in 1811. General Paulucci rebuilt the relationship from 1812 onward, managing to reconstruct trust without resolving the underlying tensions. In April 1816, Paulucci authored a secret memorandum recommending the eventual abolition of the khanate when an opportune moment presented itself — simultaneously continuing to maintain cordial relations with Mostafa Khan in his official correspondence.

Mostafa Khan also contributed positively to Russian intelligence operations: in 1813 he personally unmasked an Ottoman spy (Shakh-Suvar-bek) who had penetrated his court. His conduct during the grain crisis of 1812 and the Kakhetian revolt of the same year was assessed by commanders as fully loyal.

Later reign The appointment of General Aleksei Yermolov as Commander-in-Chief of the Caucasus in 1816 initiated the final phase of the khanate's existence. Yermolov's October 1817 circular to the Caucasian khans deliberately excluded Mostafa Khan — an early signal of his exceptional status in the new commander's assessment. In January 1818, Yermolov opened with a warm letter; by September of the same year, he had already begun military contingency planning for Mostafa Khan's removal, conveyed in a letter to Major-General Alexei Pestel commanding Russian forces in the Quba region.

The escalation from goodwill to deposition occupied roughly two years. In July 1818, Mostafa Khan voluntarily handed over seven letters he had received from Persia and Yermolov expressed no concern. By August of the same year, a crisis had emerged: it came to light that Pestel had been maintaining correspondence with Qasim Khan — the cousin Zubov had installed as Khan of Shirvan in 1796 before Mostafa Khan's return expelled him. Yermolov ordered the correspondence terminated at once, but the damage was done. For Mostafa Khan, even the existence of such a channel was existentially alarming, since deposition and replacement had already happened to him once. In January 1819, Yermolov sent him what appeared to be a congratulatory letter on the punishment of Avar rebels but which contained a veiled warning legible only to a careful reader. The abolition of the Sheki Khanate in July 1819 made the template explicit; by November Russian staff had already drafted an administrative schedule for Shirvan provincial government. In April 1820 Yermolov petitioned the Emperor to override the treaty rights on Salyan — an act that struck at the financial foundation of Mostafa Khan's rule four months before the deposition itself.

A covert intelligence operation against Mostafa Khan was conducted from Nukha. Documents report a spy visit in which an agent observed Mostafa Khan failing to raise his hat when the Emperor's name was mentioned — a gesture treated as evidence of disaffection.

Mostafa Khan was keenly aware of his situation. In 1818 he stated his own position to Madatov: "No one on a ship starts a fight with the helmsman. I have been on the ship of the Russian Monarch for twelve to fifteen years — treason is therefore impossible." He had also stated that if Russia decided to remove him, he "would obey even that without grumbling" but would "never have resolved to arm himself against so powerful a state as Russia."

The deposition