In 1813, following the Russo-Persian War of 1804–1813, Qajar Iran had to sign the Treaty of Gulistan with Russia this provided for the cession of Baku and of most of Iran's territories in the North Caucasus and South Caucasus to Russia. During the next and final bout of hostilities between the two, the Russo-Persian War of 1826–1828, the Iranians briefly recaptured Baku. However, the militarily superior Russians ended this war with a victory as well, and the resulting Treaty of Turkmenchay (1828) made Baku's inclusion in the Russian Empire definite.