TEHRAN -- Disclosure of secret dealings with the United States and other recent developments appear to have tipped Iran's Islamic leaders into a more radical revolutionary attitude and increased their hostility toward the West and its regional allies.

These shifts, in the assessment of diplomats here, have heightened the danger of armed conflict with U.S. forces building up in the Persian Gulf area and increased the likelihood of more Iranian-connected subversion in the Middle East and Western Europe.

While the atmosphere here has become more volatile, however, the leadership is trying to balance these attitudes against a desire to avoid a military confrontation with the United States in the gulf.

For that reason, Iran's military and diplomatic decisions, at least on the surface, have seemed erratic and sometimes contradictory as the hardening took place over the last six months, reversing some earlier attempts at accommodation with the West and with some of Iran's Arab neighbors. This occurred in large measure because the policy has been fought out in various, sometimes conflicting centers of clerical or revolutionary power, these sources reported.

The jockeying largely represents a competition for the ear of the aging Ayatollah Ruhollah Khomeini and, ultimately, the right to succeed him as supreme head of the Islamic Republic.

But it also represents an attempt by those leaders who had been more inclined toward accommodation with the United States to avoid being left behind by radical rivals who could accuse them of being soft on the West.

The speaker of parliament, Ali Akbar Hashemi Rafsanjani, has adopted a particularly hard line in recent declarations as part of this evolution, diplomatic and Iranian sources pointed out. His toughened attitude is in part an attempt to overcome embarrassment caused by his close identification with clandestine contacts with the Reagan administration and Israel, they said.

Rafsanjani, whose prestige and position make him the most powerful leader in Tehran after Khomeini, is widely believed to favor an eventual increase in contacts with the United States and Europe. He was influential in the secret U.S. arms dealing and in other attempts at renewing contacts abroad, including a now-collapsed effort to normalize relations with France.

But the political risks of pushing these ideas have grown markedly because of changes in the war since last winter -- including higher casualties in ground offensives and a heated-up "tanker war" in the spring -- the diplomatic standoff with France, the confrontation in the gulf and outrage over the deaths of Iranian pilgrims at Mecca last month.

As a result, Rafsanjani has shifted with the political winds toward a more radical position, or at least toward more radical rhetoric that he judges opportune for Iran's current climate, diplomatic and Iranian sources said.

With Rafsanjani's reputation for political acumen, this has been interpreted by analysts as a sign that hard-line clerics have the upper hand, at least temporarily, at several levels in the Islamic leadership that has been running Iran since the 1979 revolution.

"Rafsanjani is very clever, and he is like a weather vane for this society," said an experienced Asian diplomat.

Last Wednesday, for example, Rafsanjani suggested in an NBC News interview that Iran could intervene more forcefully to gain release of American hostages if the United States pressured Israel and Kuwait to release Shiite Moslems jailed for attacks in South Lebanon and Kuwait.

After this was interpreted in the United States as an offer of a deal, Rafsanjani denounced the network in a speech during prayers Friday and, leaning on a rifle barrel with his Iranian listeners in mind, accused the reporters of taking his remarks out of context.

Despite talk in the United States of Iranian "moderates," diplomatic and Iranian analysts here cautioned that differences in Tehran have less to do with the overall direction of the country than with personal power alliances or disagreements over specific issues.

"It is like a family whose members all agree they like to drink coffee," an Iranian journalist explained. "One person may like it black, another person may like it with milk and another may like it with sugar. But this doesn't mean they don't all like coffee."

Nevertheless, the need to keep in step with grass-roots Islamic activists among Iran's thousands of mullahs and their dedicated followers has become particularly acute because of elections for a new parliament scheduled next March.

Given Khomeini's age, estimated at 87, it is widely assumed that the next parliament will be the one in power when his rule ends, This means officials running parliament then will be in a good position to take at least a piece of the immense political and moral power wielded by Khomeini as father and guide of the Islamic revolution.

At the same time, the Revolutionary Guards have assumed steadily increasing power in running the country, from influencing political decision-making to prosecuting the seven-year war with Iraq, according to diplomats trying to explain the political change.

The group, estimated to number 300,000 soldiers, commandos and political militants, long has been the vanguard of Iran's Islamic revolutionary movement and the instrument of its more radical policies. With numbers now equal to those of the regular Army, the Revolutionary Guards also have taken a growing role in the war with Iraq and are said to have their own arms manufacturing plants and supply lines.

"There is no doubt that the Revolutionary Guards are becoming stronger and stronger and have more influence every day," a diplomat remarked.

In what was seen as a sign of their growth as a parallel political power, another diplomat said Foreign Ministry officials called in Kuwaiti and Saudi diplomats immediately after the Mecca violence and warned that something was about to happen to their embassies in Tehran the next day, but that the ministry was powerless to stop it.

The next day, on schedule, mobs sacked both embassies. The violence led to the death of a Saudi diplomatic official and created doubts among foreign diplomats about who sets foreign policy for the government.

A witness said he saw a few of those ransacking the Kuwaiti Embassy give orders to uniformed Revolutionary Guards officers who turned up to direct the crowds. This was interpreted by diplomats here as a sign that those doing the ransacking were themselves higher-ranking Revolutionary Guards, meaning the decision to sack the embassies had come from relatively high up the ladder of command in the Revolutionary Guards.

The Revolutionary Guards minister, Rafiq Doust, has been known as an activist trained in Lebanon who participated in underground attacks before the fall of the shah. Perhaps more important, he is said to be a relative of Khomeini and Rafsanjani.

Diplomats said he has more recently been regarded as a cautionary force restraining the Revolutionary Guards' military commander, Mohsen Rezai, in efforts to organize bold military action against Iraq despite reticence from the regular military. The Supreme Military Council, which directs the war, has become heavily weighted with Revolutionary Guard members, meaning Rezai has a strong voice in command decisions.

Analysts here cautioned, however, that the chain of command for the guards remains unclear and may rise above Doust or Rezai.

Among those thought likely to offer direction to the guards are Ayatollah Hossein Ali Montazeri, Khomeini's designated successor and an advocate of sreading the Islamic revolution abroad; Prime Minister Mir Hossein Mousavi; Interior Minister Ali Akbar Mohtashemi, who as ambassador to Syria helped set up Revolutionary Guard camps in Lebanon's Bekaa Valley, and Rafsanjani.

Mehdi Hashemi, an activist Montazeri aide who formerly helped direct the Lebanese camps, was arrested last Oct. 12 on a variety of charges. His arrest took place during the period when Rafsanjani was seeking to improve relations abroad, particularly with Saudi Arabia, and Saudi authorities had complained that Hashemi led a group of pilgrims who tried to enter Saudi Arabia with arms.

Hashemi's arrest led his followers to reveal the secret U.S.-Iranian contacts to embarrass Rafsanjani. This proved important, one diplomat suggested, since bringing the contacts into the open forced Iranian leaders to take stands on the issue, helping precipitate the current swing toward toughness.

The arrest culminated in a trial that ended earlier this week, with no verdict announced.

Aside from speeches in Tehran, the Mecca violence has generated widespread revulsion in Iran, particularly among the revolutionary youths who regard Saudi Arabia to be as subservient to the United States as Iran had been under the shah. Revolutionary Guards at Friday's prayers on the grounds of Tehran University chanted, "We will kill you, Fahd. We will kill you, Fahd," addressing the Saudi monarch.

This occurred despite what analysts here said was a clear desire in the government to retain relations with the Saudi royal family because of its importance in oil pricing and aid to Iraq.

In that light, the informants said, Revolutionary Guard units could decide on actions to provoke conflict in the Persian Gulf without a deliberate decision at the top in Tehran, where, according to diplomats, the desire is to avoid hostilities if possible.