Tehran was first chosen as the capital of Iran by Agha Mohammad Khan of the Qajar dynasty in 1796, in order to remain within close reach of Iran's territories in the Caucasus, before being separated from Iran as a result of the Russo-Persian Wars, and to avoid the vying factions of the previously ruling Iranian dynasties. The capital has been moved several times throughout the history, and Tehran is the 32nd national capital of Iran.