WHILE THE UNITED STATES has been taunting Ayatollah Khomeini in the Persian Gulf, the Soviet Union has begun a diplomatic opening to Tehran that could change the balance of power in the region.

Soviet Foreign Minister Eduard Shevardnadze, according to one Iranian report, is due to visit Tehran this month to sign an historic treaty with revolutionary Iran. (Other Iranian accounts predict a Shevardnadze visit by year's end.) The new accord could give Moscow what it has wanted since the days of the czars: a strategic corridor to the warm waters of the Indian Ocean and the closer economic and political links between Moscow and Tehran.

The implications of a Soviet-Iranian rapprochement are considerable, the unanswered questions numerous. What's clear is that a process of dialogue has begun. Moscow and Tehran agreed earlier this month, probably only in principle, to establish a rail link between Soviet Central Asia and the Gulf -- a move that puts Moscow closer to achieving its historic goal of a warm-water port. They also confirmed plans for Iran to export oil to the Soviet Union, initially at least by conversion of an existing gas pipeline.

The actual signing of a new Soviet-Iranian treaty of friendship would be a stunning development. Relations between the two countries have been bedeviled by the ghost of the 1921 treaty negotiated between Vladimir Ilyich Lenin and imperial Iran, which allows the Soviet Union to intervene in Iran if there is a threat against Soviet territory. Iran declared in 1979 that it was abrogating that clause and certain others, and the Iranians would probably insist that any new treaty drop these sections.

The Iranians this month have been passing the word -- in Tokyo, Bonn, Paris, Islamabad and other capitals -- that their contacts with the Soviets are serious. The message they're sending is that America's aggressive show of force in the Persian Gulf is forcing them into the arms of the Soviet bear. Much of this Iranian talk is undoubtedly propaganda -- intended to pressure the United States to ease its current anti-Iranian stance. The Iranians want us to know that they have a Soviet card, and that they are prepared to play it. As for the Soviets, they seem eager to position themselves for maximum influence in post-Khomeini Iran.

Soviet deputy foreign minister Yuli Vorontsov laid the groundwork for expanded economic and political relations during his visit this month to Tehran. According to Iranian accounts, the topics included the new rail link between the Soviet Union and the Gulf. Assuming that Moscow would be willing to foot the bill for this project, it would have three options:

Upgrading the existing railroad connection between the Soviet Union and the Gulf via the border transit point at Julfa. This route already handles roughly one-fifth of all Iranian imports and, indeed, Iranian-bound traffic has in recent years accounted for as much as 53 percent of all container traffic handled by the Soviet trans-Siberian railroad. In the process, the Soviet Union has developed considerable expertise in transferring goods despite the difference between the Soviet broad gauge and the Iranian standard gauge.

Building a short extension line -- no more than 250 miles -- between the approaches to the terminus of the Soviet trans-Caspian railroad at Krasnovodsk and the Iranian Caspian Sea port of Bandar Torkenan {formerly Bandar Shah}, which is the northern terminus of the trans-Iranian railroad.

Building a completely new north-south line designed to link the trans-Caspian railroad directly with either Bandar Abbas at the entrance to the Gulf or to Chah Behar several hundred miles to the east along the Indian Ocean coast. We believe the Soviet Union is proposing this third option, even though it involves construction of some 800 miles of new track over arid and mountainous terrain.

The railroad link would be a step toward the historic Soviet goal of an all-year, warm-water naval resupply center on open seashore. This it has never possessed. In an era where extremely quick reactions would be needed in the event of a nuclear alert, vessels have to be able to reach open water quickly without passing through straits controlled by potentially antagonistic forces -- the situation which confronts the Black Sea fleet at the Bosporus, the Pacific fleet at the approaches to Vladivostok and the Baltic fleet at the Skagerrak. A warm water port deep inside the Gulf would also not meet this requirement.

Moscow also needs to strengthen its sea lanes of communication (via the Indian Ocean) to the Pacific in the event of a Chinese rupture of the trans-Siberian railroad. Currently, Soviet naval access runs through two choke points -- the Bosporus and the Suez canal (since 1984 the Soviets have been the biggest single user of the canal). A Soviet facility on Iran's Indian Ocean coast would avoid this potential bottleneck and cut the length of the voyage to Vladivostok from 10,000 to 6,000 nautical miles.

Most Americans don't appreciate how much the Soviet Union relies on railroads, or how it plans virtually its entire military strategy -- especially its logistics -- in terms of railroads. For Moscow, the only land link between its largest potential theaters of conflict -- the European theater in the West and the Far Eastern theater 10,000 miles away on the Chinese border -- is by means of the trans-Siberian railroad; there are no highways.

Railroads still provide the only all-weather, all-season national transport network. They still carry about three-fifths of all Soviet goods traffic and two-fifths of all Soviet passenger traffic. Militarily they provide the Red Army with everything from its basic method for deploying troops to the mobile platforms for its new SS-24 intercontinental ballistic missiles. In the Soviet geopolitical view, major naval bases must also be served by rail.

Oil was the other main subject of Vorontsov's talks this month in Tehran. The Soviet Union faces severe problems in its oil industry. Although Moscow has successfully developed its natural gas resources, it has failed to reduce internal consumption of oil significantly and has been forced to cut down its oil exports to COMECON countries. For these reasons, some analysts have argued that the Soviets would find it useful to import Iranian crude.

Iran, for its part, would like to export more oil. Unlike Iraq, it has not made the investments in alternative pipelines which would enable it to increase exports and reduce its dependence on the vulnerable Persian Gulf sea route. Although Italian and Korean companies have offered to construct pipelines to facilitate Iranian oil exports, and though extensive talks have been held between Ankara and Tehran on various energy pipeline projects through Turkey, no major pipelines have yet been constructed since the Iran-Iraq war began.

Only the Soviet Union can provide an alternative channel for Iranian exports under present conditions. One possibility is renovating the disused "IGAT-One" natural gas pipeline from Iran to the Soviet Union for use as an oil export pipeline. This 750-mile line terminates at Astara in Soviet Azerbaijan, close to the underutilized Soviet oil refining center at Baku.

Oil cooperation between the Soviet Union and Iran would have great significance for OPEC. The Soviet Union is the world's largest oil producer and Soviet and Iranian oil reserves combined rival those of Saudi Arabia. If the Soviet Union is indeed moving under Gorbachev to a more market-oriented economy, then it makes considerably more sense to secure long-term access to comparatively cheap oil from a friendly neighbor, rather than to expend scarce human and material resources on the extremely costly development of its own Siberian oil fields.

In the last few weeks, by the very act of conducting discussions on railroad and pipeline links, the Soviet Union has demonstrated how truly it is the heir to czarist ambitions. Should Moscow succeed in securing a new treaty under which such projects were to be carried out -- particularly if the railroad were to be built to the Indian Ocean coast -- then the end of the centuries-old Great Game to secure a dominant influence in Persian affairs would clearly be in sight.

Lord Curzon wrote his 1892 work, "Persia and the Persian Question," precisely to draw the attention of the western powers to the dangers inherent in Russian establishment on the Indian Ocean of what he and his contemporaries termed "a second Port Arthur." Indeed, he suggested that the mineral riches of Persia could pay for the development of railroads there. Curzon would turn in his grave at the thought that such a development might be carried out by the Soviet Union.

We have found no trace whatsoever in recent accounts of Soviet-Iranian discussions of any mention of naval facilities for the Soviet fleet. But we believe the logic is inescapable: The Soviet Union is still driving for an all-year warm-water port on an open seashore, and its chosen link is the railroad. Building a pipeline and accepting Iran's abrogation of the offensive clauses of the 1921 treaty may be the price Moscow is ready to pay to secure this cherished objective.

When you consider what the Reagan administration was ready to sacrifice in its quest for improved relations with Iran, the Soviets are getting it cheap.

Milan Hauner teaches history at the University of Wisconsin and is the author of "India in Axis Strategy." John Roberts is the Washington correspondent for Middle East Economic Digest.