As early as the 1510s, Tbilisi (and the kingdoms of Kartli and Kakheti) were made vassal territories of Safavid Iran. In 1522, Tbilisi was garrisoned for the first time by a large Safavid force. Following the death of king (''shah'') Ismail I (r. 1501–1524), king David X of Kartli expelled the Iranians. During this period, many parts of Tbilisi were reconstructed and rebuilt. The four campaigns of the king Tahmasp I (r. 1524–1576) resulted in the reoccupation of Kartli and Kakheti, and a Safavid force was permanently stationed in Tbilisi from 1551 onwards. With the 1555 Treaty of Amasya, and more firmly from 1614 to 1747, with brief intermissions, Tbilisi was an important city under Iranian rule, and it functioned as a seat of the Iranian vassal kings of Kartli whom the shah conferred with the title of vali. Under the later rules of Teimuraz II and Heraclius II, Tbilisi became a vibrant political and cultural center free of foreign rule—but, fearful of the constant threat of invasion, Georgia's rulers sought Russian protection in the 1783 Treaty of Georgievsk. Despite this agreement, the city was captured and devastated in 1795 by the Iranian Qajar ruler Agha Mohammad Khan, who sought to re-establish Iran's traditional sovereignty over the region.