TEHRAN, DEC. 27 -- With the United States and Iraq, its two great enemies, locked in explosive confrontation, the Islamic Republic of Iran is working for advantage from a delicate and dangerous position in the Persian Gulf crisis.

Day after day, Tehran's ruling clergymen publicly refine a policy designed to make Iran a winner, however the crisis evolves, and to do so as a non-combatant.

President Ali Akbar Hashemi Rafsanjani, seeking a politically righteous position, is dishing out blame and warnings to all foreign powers and watching his back at home.

Iraq, he declared last week, "has perpetrated an obscene act by invading Kuwait and this invasion is not acceptable to Iran." But he also insisted that U.S.-dominated forces in Saudi Arabia are no less a threat to stability in the gulf.

"We are feeling very uneasy over the fact that the Iraqi people may be hurt by the Americans," Rafsanjani told a group of Iranian university students.

Iran's long isolation in world affairs has led some of its politicians to suspect the worst: that Iraq and the United States are preparing to cut some sort of deal that will damage Tehran. In hotel coffee shops here this week, Iranians buzzed with rumors of conspiracy, despite a dearth of evidence.

So despite his continued political mastery over opponents among the radical clergy, the centrist president can afford no missteps in handling Tehran's position on the crisis. With Washington and Baghdad involved, policy is political dynamite.

What seemed like a plum for Tehran in August -- Western powers preparing to bash Iraqi President Saddam Hussein for his invasion of Kuwait, and Saddam in response delivering Iran a peace treaty to protect his eastern flank -- now looks in December like a windfall that will need careful protection.

"Any result that leaves Saddam in place strengthens Iraq vis-a-vis Iran," explained an Asian diplomat here. "It would humiliate the Arabs who stood against him, and if Saddam's stock rises in the Moslem world, it does so at the expense of Iran.

"They {Iran's leaders} want a short, sharp war, and would probably agree to a short-term American presence in the gulf once it's over. But if the fighting drags on, it gives Rafsanjani a problem on policy. The radicals will say, 'Why are we siding with the Great Satan against our Moslem brothers?' "

Last week the Iranian military was flexing its muscles along the lower gulf shores, staging amphibious maneuvers out of the big naval base at Bandar Abbas on the strategic Strait of Hormuz.

Despite the maneuvers, Western and Asian diplomats in Tehran say they are convinced that Iran wants no part in a war if it comes to the gulf. But, the diplomats say, the revolutionary government, which was obsessed in its early years with internal problems, intends to be part of any post-crisis regime for maintaining stability in the region.

The stakes are high. The economy of this country of 55 million people was knocked comatose by the brutal 1980-88 war with Iraq, and Rafsanjani's cabinet of technocrats needs breathing space to nurture a recovery. Living standards in this gritty capital of 10 million or more are slipping even in peacetime.

"They desperately want to sit this out," a Western diplomat said. "They simply cannot afford another war at this point."

The advantage of the Iranian position so far is evident in the ledgers of the National Iranian Oil Co., the government petroleum monopoly and source of nearly 90 percent of the country's hard-currency revenue. While Iran has not increased oil output since an international embargo shut down exports from the fields of Iraq and Kuwait, higher world prices have brought an additional $5 billion into Tehran's cash-starved treasury.

Meanwhile, the leadership's policy on the crisis keeps evolving.

"At the beginning," another diplomat said, "the government here appeared eager to see Iraq flattened and Saddam finished off. Then, as the United States increased its forces, the concern shifted to the prospect that the Americans would stay on" in some sort of post-crisis security arrangement. "For a regime that claims to be a leader of the Islamic world, that prospect puts them in a terrible position."

Mohammed Javad Larijani, an adviser to the Foreign Ministry, explained the Iranian position in a Tehran newspaper: "The security systems the United States is creating are intended to contain Islamic Iran -- all because we advocate Islam. Should we abandon the idea, should we no longer be a threat to the bullies?"

Publicly, the government insists that the Western forces must leave the region if Iraq withdraws from Kuwait. Rafsanjani has indicated that Iran is prepared to become the policeman of the gulf, a role once filled by the U.S.-backed monarchy of the late Shah Mohamed Reza Pahlavi, who was driven from power nearly 12 years ago by the Islamic revolutionaries.

The constant travels of Foreign Minister Ali Akbar Velayati in the past month indicate that Iran is doing some sort of post-crisis spadework, Tehran-based diplomats say.

Velayati has called on leaders of the gulf states, Turkey and Egypt, all key Islamic players in the crisis. Official reports say he is tending to bilateral relations, but the diplomats speculate he might be offering Iranian services as the policeman.

Yet Iran's economic interests lie with cooperation with the Western powers and their Arab allies on the western side of the gulf, who would insist on some sort of counterweight to Iranian influence in the strategic waterway, heart of a region that yields 40 percent of the oil on the world market.

The crisis, the Western diplomat said, "has given them a window to jump back into the Western world," the only source of sufficient development funds to raise the Iranian economy from its sickbed. Only in recent months have foreign businessmen been sufficiently encouraged by Rafsanjani's stewardship of the economy to return to Tehran talking investments.

"They have thrown their kitty in with the United Nations" and the West, the diplomat noted, observing that Iranian compliance with the Security Council economic embargo against Iraq has been largely leak-proof.

But while Rafsanjani may open doors to the West for the sake of the economy, he would not steer his regime into the Western political camp. Revolutionary Tehran still considers itself the font of pure Islam and a protector of the faith and the Palestinian cause.

That means it will work for an Islamic stability in the gulf, and, ultimately, Iraq would be the counterweight in that equation, whatever the outcome of the present crisis. Iraq's population is only a third of Iran's. Even Baghdad kept Kuwait, its access to gulf waters would be but a fraction of Iran's, which, with five naval bases and eight major warships, amounts to a naval powerhouse in the area. But Iraqi governments have historically shown a determination to project their power down the gulf.

"Iraq and Iran will always be the balancing forces in the region," a high-level Iraqi Foreign Ministry official said in Baghdad recently, a comment underlining the likelihood that the two countries will continue to play important roles in the gulf.

That presumed role for Iraq, with or without Saddam, is what has the conspiracy rumors flying around the coffee shops and newspaper columns of Tehran, launched by President Bush's "extra mile" effort for Washington-Baghdad talks.

"For the first time, the Iranians are starting to think seriously about American policy in the crisis," the Western diplomat said. "They're starting to ask themselves whether the United States might choose not to thump Saddam and where that would leave Iran."