By the early 16th century Baku's wealth and strategic position attracted the attention of its larger neighbours; in the previous two centuries, it was under the rule of the Iran-centred Kara Koyunlu and Ak Koyunlu. The fall of the Ak Koyunlu brought the city immediately into the sphere of the newly formed Iranian Safavid dynasty, led by king ("shah") Ismail I (). Ismail I laid siege to Baku in 1501 and captured it; he allowed the Shirvanshahs to remain in power, under Safavid suzerainty. His successor, king Tahmasp I (), completely removed the Shirvanshahs from power and made Baku a part of the Shirvan province. Baku remained as an integral part of his empire and of successive Iranian dynasties for the next centuries, until ceded to the Russian Empire through the 1813 Treaty of Gulistan. The House of Shirvan, which had ruled Baku since the 9th century, was extinguished in the course of Safavid rule.