By the late 17th century, the Iranian Safavid dynasty, which neighbored both empires and had been one of the greatest rivals for Turkey for centuries (16th–19th centuries), had been heavily declining. Taking advantage of the situation, Russia and the Ottoman Empire conquered swaths of its territory comprising contemporary Dagestan, Azerbaijan, and Northern Iran, which was taken by Peter I in the Russo-Persian War (1722–1723); the Ottomans took the territory to the west, comprising modern day Armenia, parts of Eastern Anatolia, as well as western Iran. The gains by both were confirmed in the Treaty of Constantinople (1724). For a few years, they bordered each other along a large territory in the Caucasus, which caused further frictions.