IRAN IS surprising everyone, except perhaps the Ayatollah Khomeini, and beating Iraq, which invaded 18 months ago in the hope of a quick victory over a regime supposedly incapacitated by revolutionary turmoil. Iran's armies seem near to ousting Iraq's now-forlorn legions from Iranian territory, and the new question is whether the ayatollah will keep on going and strike out for Baghdad. Whether Saddam Hussein, who before the war paraded his dreams of dominating the Gulf and establishing Iraq as the leader of the Arab world, can hold on to either his power or his life becomes increasingly uncertain.

The immediate issue is the political shape of the Gulf when the war dies down, and the evident answer is that further instability is in store. Iran will be, again, the principal regional military power. There will be a difference: the Tehran regime's eagerness to export its Islamic revolution poses a threat to other Gulf countries and may tend to draw them together. The United States may come under pressure to bolster the Arab side against Iran's further depredations. This prospect is welcomed by some in Washington. It provided one of the impulses that led the administration recently to remove Iraq from the list of countries supporting international terrorism, notwithstanding Iraq's continuing operations against Israelis and Kurds.

It would be, however, extremely shortsighted of the United States to plunge after Arab favor in an unbalanced way. Iran, with its immense resources, remains the strategic prize in the Gulf. The Soviet Union, close by geographically and active politically, has been working overtime to pin down its position with various Iranian elements. Some students of the situation have pointed out what an anomaly it would be if the United States, having directed its policy toward the establishment of a Rapid Deployment Force to prevent a Soviet military breakthrough to the Gulf's vital oil fields, were to wake up one morning and find that Moscow had made a political breakthrough.

The United States has been poorly placed to deal with Iran since the fall of the shah and the subsequent hostage crisis, not to speak of the continuing excesses of the Khomeini regime. It would be a tremendous strategic error, however, not to act in whatever way possible to fulfill the spirit of Jimmy Carter's assertion of 1980 that "we have no basic quarrel with the nation, the revolution or the people of Iran . . . (and following the release of the hostages) we are prepared to work with the government of Iran to develop a new and mutually beneficial relationship." The administration could avoid the question while the war between Iran and Iraq went on inconclusively. But now that Iran appears to be winning, it will have to face up to it.