which separates it from the provinces of Moghan and Armenia". Shirvanshahs Shirvanshah also spelled as Shīrwān Shāh or Sharwān Shāh, was the title in medieval Islamic times of a Persianized dynasty of Arabic origin. They ruled the area independently or as a vassal of larger empires from 809 A.D. up to 1607 A.D. when Safavid rule became firmly established. Safavid, Afsharid and Qajar eras When the Shirvanshah Shah dynasty was ended by the Safavid Shah Tahmasp I, Shirwan formed a province of the Safavids and was usually governed by a Khan, who is often called Beylerbey. Shirvan was taken by the Ottomans in 1578; however, Safavid rule was restored by 1607. In 1722, during the Russo-Persian War (1722–1723), the Khan of Quba, Husayn Ali, submitted to Peter the Great and was accepted as his dignitary. The Treaty of Saint Petersburg (1723) forced the Iranian king to recognise the Russian annexation. By the treaty between the Russian and Ottoman Empires in the year 1724, the coast of the territory of Baku, which was occupied by the Russians, was separated from the rest of Shirvan, which was left to the Ottomans. It was only when Nader Shah defeated the Ottomans (1735) that the Russians ceded back the coastal land and the other areas in the North and South Caucasus as conquered in 1722–1723 from Safavid Iran conform the Treaties of Resht and Ganja, and the area became part of the Afsharid Empire, by which century long Iranian rule was restored. Qajar Iran to the Azerbaijan SSR When the Qajars had succeeded in restoring the unity of Persia, the sons of the Khan were no more able to maintain their independence like the other Caucasian chiefs and had to choose between Russia and Persia. The Khan of Shirwan, Mustafa, who had already entered into negotiations with Zubov, submitted to the Russians in 1805, who occupied the Persian cities of Derbend and Baku the next year (1806) during the Russo-Persian War (1804–1813), but soon afterwards he made overtures to the Persians and sought help from them. By the Treaty of Gulistan (12/24 October 1813) following the end of the 1804–1813 war, Persia was forced to cede its territories and regions comprising Darband, Quba, Shirwan and Baku, while giving up all claims on them as well. Nevertheless, Mustafa continued to have secret dealings with Persia. It was not until 1820 that his territory was occupied