The downing of an Iranian airliner by a U.S. warship came as Iran's leaders were inching toward better relations with some Western nations amid persistent reports that Ayatollah Rubollah Khomeini is dying.

But Sunday's tragic shooting down of Iran Air Flight 655 with 290 people aboard is bound to spark a new wave of virulent anti-Americanism and provide more grief for the propaganda mill of Ali Alibar Hashemi Rafsanjani, the power behind Khomeini.Rafsanjani, the speaker of the Iranian parliament and the ayatollah's newly appointed military chief, has moved to the fore recently amid mounting reports that his main backer, Khomeini, 88, is dying of cancer.

Western diplomats believe Rafsanjani, although moving gingerly toward mending relations with other Western countries, needs "limited confrontation" with the United States to prove his revolutionary credentials at a time of serious infighting among the ruling clergy and economic hardship caused by the nearly 8-year-old Persian Gulf war.

Rafsanjani's task has been made more difficult by a stinging series of defeats Iraq has recently inflicted on Iran in the war.

Rafsanjani will most likely use the U.S. downing of the civilian airliner and Iranian clashes with U.S. forces in the gulf to bolster his position as the keeper of the faith by taking advantage of the renewed anti-Americanism that is bound to sween Iran, a Western diplomat said.

"Rafsanjani thrives on confrontation with the Great Satan," the diplomat said using the phrase coined by Khomeini to describe the United States.

"The Iranians will play up the battles with the Americans as much as possible because this is a vote-winning exercise," the diplomat said.

"But the tragic crash of the passenger liner has given Rafsanjani a surprise propaganda gift."

During the long period of Iranian victories on the war front, Iranian television screens were filled with pictures of "our heroic boys" battling the Iraqi foe.

"Such a diversion made some Iranians forget their empty stomachs," the diplomat said. "But Iranian defeats definitely do not make good television footage."

Anti-American demonstrations do.

At the same time, however, Iran needs to look elsewhere in the West for friends, or at least improved relations, to reduce its international isolation in the wake of its military defeats and economic problems.

Iran has paid for the war with its oil. but declining oil revenue is not enough, and in recognition of this, Iran restored diplomatic relations with France last month.

This should net it a badly needed $2 billion Iran lent France during the rule of the shah a decade ago.

Iranian officials have also held talks with British and Canadian officials, and prospects for a normalization and improvement in ties and trade look promising.

Improving prospects for its shrinking economy are vital if Rafsanjani is to have any hope of continued popular support.

Rafsanjani announced over the weekend radical changes for the demoralized armed forces, including an eventual merger of the conscript army with the elite, all-volunteer Revolutionary Guards.

This decision pits Rafsanjani once more against a key rival, President Ali Khamenei, who declared his total opposition to the move.

Rafsanjani also announced drastic changes in the allocation of resources for Iran's shrinking war economy.

The move can only add to his growing number of foes, but they could be held in check if Rafsanjani can ride on a wave of anti-American emotion.