With the United States ranking near the top of the Islamic republic's enemy list, the Soviet Union has been reaping political and strategic advantages from the Iranian revolution.

Gone are the days when Washington could depend on Shah Mohammad Reza Pahlavi to back U.S. policy on the Middle East and help counter Moscow's aims in the region.

Among its many other consequences, the downfall of the shah has shattered the illusion - carefully built up by the Uranian monarch and brought by the United States - that Iran was a bastion of stability in a turbulent but vital area. This vision of Iran as a stable, pro-American force in the Middle East was cited to justify the vast U.S military and economic commitments in the country. The repudiation of this relationship and the new government's instablility have helped boost Soviet stock in the area, if for no other reason than because U.S. influence has been depressed.

Nevertheless,not everything is in Moscow's favor.

The Soviets are still widely distrusted here, by the government of Ayatollah Ruhollah Khomeini and by the Iranian left. Moreover, they have been stung economically by reduced supplies of Iranian gas and the prospect that major contracts for expensive development projects may be canceled.

Because of the distrust, the Soviets have been unable so far to develop ties to the new Iran that are as close as they apparently would like. The Soviet ambassador in Tehran reportedly has visited Khomeini more often than any other diplomat, but the Moslem leader has not spared his northern neighbors in his latest pronouncements, blaming them for stirring up unrest in Iran.

Typical of the attitude among Khomeini followers is a spray-painted stencil that appears on many Tehran walls. It shows the letters "U.S.A." side-by-side with a hammer and sickle, each of the symbols crossed out with a big X.

In a recent interview, Khomeini aide Sadegh Ghotbzadeh, the head of National Iranian Radio and Television, described the Soviet role in Iran as "very dirty." But he said the government is still "trying to establish proof" of exactly what the Soviets have been up to particularly in alleged efforts to stir up trouble among minorities.

On the whole, though, Washington's loss has been Moscow's gain. In fact, there are fears among U.S. officialdom that the Soviets may have been able to take advantage of the revolutionary turmoil to compromise U.S. military secrets.

In their overriding concern with propping up the floundering government of Shahpour Bakhtiar, the shah's last prime minister, American military and Central Intelligence Agency officials neglected contingency plans for evacuating sensitive equipment and materials, informed sources say.

"Everything was left behind," one well-placed source said. "It was a disgrace."

He said it was not immediately possible to assess the extent of U.S. losses. But given the breakdown in security, the assimilation into Khomeini forces of guerrillas and other politically diverse elements and the general anti-American feeling, "it is reasonable to assume that U.S. secrets have been compromised," the source said.

While the shah was still in power the Soviet Union maintained about 40 full-time intelligence officers in Iran, most of them attached to the Soviet Emabassy here, according to Western analysts. Since the revolution, they believe Soviet intelligence-gathering capability in Iran probably has increased.

For the Soviets this is a source of great satisfaction, according to diplomats here.

"There have been setbacks on both sides, but politically the situation is much more to the advantage of the Russians," a European diplomat said. "I think they're very pleased with the situation."

Whereas Iranian foreign policy under the shah was aligned with U.S. efforts to contain Soviet influence in the Middle East, the Islamic republic's new posture on a number of issues squares with Soviet policy in the region. Repudiating the shah's ties with Israel, his opposition to an independent Palestinian state and his tacit support for Egypt's peace initiative, the new government in Tehran has joined most Arab countries in severing diplomatic relations with Cairo and condemning the U.S.-sponsored peace treaty with Israel.

The government has opened contacts, if not full relations as yet, with Soviet friends including Cuba, Libya and South Yemen. The Palestine Liberation Organization has moved into the former Israeli mission and three other buildings in Tehran. And the new Iranian government has dropped its support of efforts by Oman's Sultan Qabus to avoid a new flareup of a Marxist rebellion in the Dhofar portion of the country.

Although the Soviet Union also supplied military equipment ot Iran - including jeeps, trucks, armored personnel carriers and tracked vehicles - it never had military contracts here on the scale of the American ones. The Soviets regularly criticized the shah's arms buildup and were annoyed by Iran's membership in the Central Treaty Organization created to guard against Soviet expansion in the region.

The new provisional government has since pulled out of CENTO, reflecting its new policy of nonalignment.

The Soviet Union and Iran have, however, been at loggerheads over a Moslem rebellion in neighboring Afghanistan. The pro-Moscow government in Kabul has accused Iran of helping the rebels, while Iranian cleergymen have grown increasingly strident in condemning "repression" of fellow Moslems by the Soviet-backed state.

Probably the most damaging element for Moscow in the new relationship with Iran has been reduced deliveries of Iranian gas to the Soviet Union via the Igat-1 pipeline.

The curtailed gas deliveries, a result of lower oil production, have forced the Soviets to make costly redistributions of energy supplies for industries in the Transcaucasus region.

Soviet planning stands to suffer an even bigger setback if a second gas delivery project, Igat-2, does not go ahead. A project considered unlikely to proceed is expansion of the Soviet-built Isfahan steel mill. Earlier plans had called for tripling its capacity.

In an effort to sort out the two countries' economic dealings, a senior Soviet foreign trade official, Semyon Skatchkov, made an extended visit to Tehran last week. A visit by a Soviet banking delegation also is in the works.

Regardless of the immediate problems, diplomats say, the Soviets can take comfort in the fact that the left is gaining support as the Khomeini camp increasingly shows its conservative colors.

The trend in Iran toward political polarization advances the possibility of further unrest, which could eventually lead to another revolution and the installation of a leftist government that if not openly pro-Soviet, would at least be more sympathetic to Moscow.

"What Khomeini is creating now is discontent among the educated and middle class because the revolution didn't bring about all the freedom they asked for," a diplomat said. "Perhaps people won't be as afraid to try socialism or communism in the future."

With this situation and the possibility of more agitation among provincial minorities, some observers feel time may be on Moscow's side.