The Iranian government today announced the explusion of a high-ranking Soviet diplomat on charges of spying in a move that emphasized the worsening relations between the two countries since the Soviet invasion of neighboring Afghanistan last December.

The Iranian Foreign Ministry said First Secretary Vladimir Golvanov "was arrested last week while contacting and exchanging espionage documents against the interests of the Islamic republic with a foreign national in Tehran."

It added that Golvanov was declared persona non grata and asked to "leave Iranian soil within 24 hours." It was understood that he had already left the country.

A Soviet Embassy official denied any knowledge of the incident and the Iranian government declined to provide any further information.

Among the questions that could not be answered were the identity, nationality and fate of the other foreigner, the nature of the information passed whether Golvanov was actually imprisoned since last week, which would be a violation of diplomatic immunity.

Golvanov, who had served here for three years, is the first Soviet diplomat to be expelled since the ouster of the regime of Shah Mohammad Reza Pahlavi and the assumption of power by the Islamic republic under the leadership of Ayatollah Ruhollah Khomeini. Two Iraqi diplomats were expelled earlier this year during the flareup of border fighting of Iran and Iraq.

Despite harsh Iranian criticism of the Soviets over Afghanistan, Moscow has sought to take advantage of Iran's even worse relations with the United States because of Tehran's continued holding of the 53 American diplomatic hostages.

Moscow has offered the possibility of increased trade across the border along the Caspian Sea to ease the effect of Western economic sanctions, but there is little evidence of greater traffic in the sparsely populated area. b

Last week the Soviets refused to allow Iranian ships to traverse the rivers and canals connecting the Caspian and Black seas.

In addition the countries have been unable to reach agreement on a price for Iran's natural gas, which has been piped to the Soviet Union for years under an agreement reached during the shah's government.

Khomeini has taken the line that Iran is "neither Western nor Eastern." The United States has been termed "the great Satan" but to many Iranians the Soviet Union is "the lesser Satan."

The seized American Embassy has become known to Iranians as the "nest of spies" because of longtime CIA activity, but many have also long accused the Soviets of espionage activity. The shah evicted several Soviet diplomats.

One test of the Soviet determination to continue trying to take advantage of hostile U.S.-Iranian relations will come in Moscow's decision whether to follow normal Soviet practice and expel an Iranian diplomat in Moscow of similar rank.

Although Golvanov was the first Soviet diplomat expelled since Khomeini took power, there was an incident last year in which a Soviet military attache, Col. Vladimir Lugovkian, was hastily withdrawn after a leftist Iranian politician was arrested on charges of spying for the Soviets. The politician, Mohammed Reza Saddati, is a member of the Mujaheddin guerrilla group and is still in prison awaiting trial.