MOSCOW, AUG. 25 -- The Soviet Union introduced the world's strictest anti-AIDS law today, providing a five-year jail term for carriers of the lethal virus who have sexual contact with another person, even if the infection is not passed on.

The law, which applies to Soviets and foreigners living in the U.S.S.R., also subjects those who knowingly transmit an AIDS infection to up to eight years' imprisonment and empowers the police to apprehend suspected carriers and force them to be hospitalized for testing.

Passed by the Supreme Soviet, or legislature, the tough measures say that those "of whom there are grounds for assuming that they are infected" may be brought to hospitals with the help of officials from the Interior Ministry, which controls the police.

Today's law came in response to a growing Soviet problem with acquired immunity deficiency syndrome. In the past year, the number of officially registered cases here multiplied more than tenfold, although it remains far below figures registered in the United States and elsewhere in the West.

Publication of the new measures by the official news agency Tass accentuates an AIDS prevention campaign, waged in the Soviet media, that warns against the dangers of sexual contact with Americans, Africans and other foreigners.

Accounts of the disease abound, particularly in the mass-circulation newspapers read widely by Soviet youth. A recent issue of the official youth newspaper Komsomolskaya Pravda told of a young homosexual Soviet diplomat who caught the AIDS virus in Tanzania. On return to the U.S.S.R. he proceeded to take 24 male lovers, leaving a trail of 14 infections, including the new wife of one sexual partner and their baby daughter. Now the diplomat is dying.

One reaction to the anti-AIDS campaign has been panic. Up to 100 Soviets visit the AIDS testing center in Moscow each day, the Soviet press has reported.

When another center opened last spring in the Uzbek capital of Tashkent, doctors reported a flood of patients who thought that every sign of illness marked the early symptom of AIDS, the government's official newspaper Izvestia reported.

Another reaction has been a Soviet-style conservative backlash. According to a Komsomolskaya Pravda article published three weeks ago, a group of young Soviet doctors recently wrote to the country's leading AIDS specialist vowing to "do everything possible to hinder the search for an AIDS cure." Their reason: a preference for witnessing the disease wipe out homosexuals, drug addicts and prostitutes, identified as the highest risk groups here.

The Soviet media is gradually shifting from propagandistic charges, such as that the CIA was spreading AIDS through biological warfare, to more substantive articles about it. But the Soviet public seems woefully uninformed about the disease.

One popular rumor circulating in Moscow was that mosquitoes were a principal carrier. Izvestia told of a man in Tashkent who visited an AIDS testing center because he was concerned about the illness of his cow.

Specialists here admit that attitudes here discouraging frank discussion of sex have hampered public education on AIDS, which is usually thought to be spread through exchange of blood or semen.

By delaying admission that the problem existed, Soviet authorities also lost time in stopping its spread, journalist A. Novikov said in the Komsomolskaya Pravda article.

During the early 1980s, when the first cases began to surface in the West, Soviet authorities were loath to admit that this country had homosexuals, drug addicts or prostitutes -- let alone the disease.

A Soviet scientist told an AIDS conference in Paris last June that 12 cases of AIDS carriers had been found in the Soviet Union.

Last month, the official newspaper Socialist Industry reported 130 registered cases of AIDS in the Soviet Union, including 19 Soviet citizens. This represents more than 10 times the 1986 tally, but still is a miniscule percentage of American AIDS patients. "The actual number of cases is obviously far higher," however, the newspaper said. Among foreign students alone, up to 1,000 are likely to be carrying AIDS, Vadim Pokrovskii, the leading Soviet specialist, has estimated.

"Citizens of the U.S.S.R., as well as foreign citizens and stateless persons living or staying in the territory of the U.S.S.R., may be bound to take a medical test for the AIDS virus," the decree said.