Iran was the seat of the ancient kingdom of Elam (c. 3000-640 B.C.), which competed with the Mesopotamian states to its west. The area was settled by the Iranians, an Aryan people, c.1800 B.C., from whom arose the Medes, Persians and Parthians. At various times from the 7th century B.C. to the 7th century A.D., Persian states dominated the Middle East, at times ruling territory from Egypt and Thrace to India. Debilitating wars with Rome weakened Persia, making it easy prey to the Arabs in the 7th century. With the decline of the caliphate after 1040, Persia was torn by centuries of war and anarchy, complicated by Turkish immigration and Mongol invasions (13th-15th centuries). National unity was re-established under the Safawid dynasty (1502-1722), and Persia re-emerged as a dominant power in the region. After the mid-18th century, Persia weakened, losing its outlying provinces (Afghanistan, the Caucasus, etc.) and gradually fell under European influence. Russia and Britain carved out spheres of influence in the 19th century and occupied portions of the country in World War I and World War II. In 1921, Riza Pahlavi, a military chief, led a coup and assumed virtual control of the government, becoming shah in 1925. He began to radically modernize Persia, a program continued by his son and successor, Mohammed Riza Pahlavi. Mohammed Riza Pahlavi attempted to modernize Iran rapidly and used the country's substantial oil revenues toward this end. While his policies brought a social and economic transformation of Iran, the shah ruled absolutely, and political opposition was suppressed. Increasing dissatisfaction with the regime brought the coalition of many disparate elements in Iranian society. Anti-government riots brought martial law in September 1978, but the government's position deteriorated rapidly. On Jan. 16, 1979, the shah left Iran, and in mid-February, the caretaker regime of Shahpur Baktiar, a longtime opponent of the shah, was overthrown amid popular demonstrations by supporters of Ayatollah Ruhollah Khomeini. On April 1, the Ayatollah declared Iran an Islamic republic and immediately set about creating a theocratic regime, reflecting staunchly conservative Islamic values. Khomeini accused the United States, which had strongly supported the shah, of being the source of most of the country's problems. Relations between the two countries quickly deteriorated, and in November 1979, student demonstrators seized U.S. embassy personnel in Tehran. The embassy staff was held hostage, pending the return of the shah to Iran, where he was to be tried by revolutionary courts. The death of the shah in July 1980 did not bring a resolution of the problem, which continued until the captives' release in January 1981. In September 1980, Iraq attacked Iran, beginning a bitter war that drained the resources of both nations, until a cease-fire ended hostilities in 1988. Political and economic instability became the norm in Iran. Political terrorism and government repression, as bad or worse than under the shah, were institutionalized by the Muslim clerics. In the 1990s there has been some movement toward liberalization, driven by increasing popular discontent with the repressive fundamentalist regime. In 1997, Mohammed Khatami, a moderate Shiite Muslim cleric was elected president, leading many in the West to hope for a gradual moderating of the Iranian government's policies.