The kingdom of Kartli was a battleground of the Ottoman-Safavid wars, conflicts among neighboring Georgian and Caucasian rulers, and of its own civil wars into the 18th century. Beginning from 1550, and more strictly since 1614, the Georgian rulers pursued the "politics of compromise" with their Persian overlords. This implied that Persia allowed Kartli or any other region under their rule to retain a considerable autonomy and the Georgian dynasty of Bagratids to hold the royal throne provided they adopted Islam and remained subordinate to the shah. In Georgian documents, the Georgian rulers continued to be styled as kings, while Persian official documents referred to them as the wāli ("viceroy") of Gorjestān, underscoring their subservience to the shah. Many members of the aristocratic elite of Kartli filled high positions in the Persian military and administration and several noble women entered the shah's harems. This situation changed in 1745, when, with the permission of Nāder Shah, Teimuraz II was crowned as king of Kartli according to Christian customs. In 1748, Kartli became essentially independent, with only formal side of Persian vassalage still observed. In 1762, Kartli was united with the neighboring eastern Georgian kingdom of Kakheti into a single state, which placed itself under the Russian protectorate in 1783, but it suffered the devastating Persian invasion in 1795, when Agha Mohammad Khan of Persia's newly established Qajar dynasty sought to bring Georgia again under Persian hegemony. The weakened kingdom was annexed by the Russian Empire in 1801 and this new rearrangement was confirmed in the Treaty of Gulistan in 1813 following the Russo-Persian War (1804-1813).