Azerbaijan is the name for the stretch of land contained by the southern slopes of the Caucasus Mountains on the north, the Caspian Sea on the east, and the Armenian highlands in the west: In the south its natural boundary is less distinct, and Azerbaijan merges here with the Iranian plateau. From the time of ancient Media and Achaemenid Persia, Azerbaijan was drawn into the orbit of Iran. One theory for the etymology of its name gives a derivation from Atropatenes, a Persian satrap in the time of Alexander the Great. Another, more popular explanation traces its origin to the Persian word azer"fire" - hence Azerbaijan "Land of Fire," because of its numerous Zoroastrian temples, their fires fed by the plentiful local sources of oil. Azerbaijan retained its Iranian character even after the conquest of the region by Arabs and conversion to Islam in the mid-seventh century; only some four centuries later, with the influx of the Oghuz Turks under the Seljuk dynasty, did the country acquire a large proportion of Turkic inhabitants. The original population became fused with the immigrant nomads, and the Persian language was gradually supplanted by a Turkic dialect that evolved into a distinct "Azeri" or Azerbaijani language. After the thirteenth-century Mongol invasions, Azerbaijan became part of the empire of Hulagu and his successors, the IIKhans, then passed under the rule of the Turkmens who founded the rival Qara Qoyunlu and Aq-Qoyunlu states. Concurrently, in the fifteenth century, there flourished a native Azerbaijani state of Shirvan shahs. In the early years of the next century Azerbaijan became the power base of another native family, the Safavids, who through a vigorous policy of centralization built a new Persian kingdom on the foundation of the Shia branch of Islam. The Safavid dynasty lasted for more than two hundred years; its rule ended in 1722, having been undermined by internal strife and the Afghan invasion.