In 1813, as a result of the Treaty of Gulistan, the Russians gained control over southern Dagestan and most of what is the contemporary Azerbaijan Republic. The 1828 Treaty of Turkmenchay indefinitely consolidated Russian control over Dagestan and other area's where the Lezgins lived and removed Iran from the military equation. The Russian administration subsequently created the Kiurin Khanate, later to become the Kiurin district. Many Lezgins in Dagestan, however, participated in the Great Caucasian War that started roughly during the same time the Russo-Persian Wars of the 19th century were happening, and fought against the Russians alongside the Avar Imam Shamil, who for 25 years (1834–1859) defied Russian rule. It was not until after his defeat in 1859 that the Russians consolidated their rule over Dagestan and the Lezgins.