The Soviet Union has canceled the visa of a leading American publisher on the eve of his departure to attend the second Moscow Book Fair.

Robert L. Bernstein, chairman and president of Random House, said today he received his visa last Wednesday and was informed Thursday that it had been revoked.

Bernstein was given no explanation, and a spokesman for the Soviet embassy in Washington said that Soviet policy is never to explain visa decisions.

The action against Berstein dims American publishers' enthusiasm for a fair that is very important to Soviet officials. Observers regarded it as out of keeping with the recent pattern of Soviet actions, and pointed out that it came before the Soviet-American weekend confrontation over the departure of Soviet ballerina Ludmilla Vlasova.

Bernstein has a long record as a defender of human rights and critic of Soviet human rights abuses, but the Soviet Union was well aware of his background when it first indicated that Random House could participate in the fair six months ago. The fair opens Sept. 4.

"Their decision is both morally offensive and fraudulent," Bernstein said. "The Soviets accepted our application, accepted our fees and, as recently as two weeks ago, accepted payment for a dinner for Soviet writers that I was to have hosted with another publisher."

The State Department urged the Soviets to restore Bernstein's visa, and indicated that Secretary of State Cyrus R. Vance supported the appeal, but officials were informed this morning that the refusal had been affirmed.

"We regret this decision by the Soviet Union. Mr. Bernstein is an outstanding American," Assistant Secretary of State Hodding Carter said.

The Association of American Publishers also worked to reverse the Soviet decision, and issued a statement saying that Soviet public claims that the book fair is an example of translations into reality of "the lofty principles" of the United Nations and the Helsinki Agreement "are directly refuted by the actions taken with respect to Mr. Bernstein."

Bernstein said, "It is tempting in a situation such as this to cancel Random House's participation in the book fair and to urge other publishers, who might as readily have been the targets of this capricious action, to do so as well."

He decided, however, not to send the four other Random House representatives who had been planning to attend the fair and who still have visas, but to allow Random House books already in the Soviet Union to be exhibited.

The Soviet decision to single out Bernstein came two years after the first Moscow Book Fair, which Bernstein chose not to attend because of persecution of Soviet writers and his inability to determine from Soviet authorities which books they would bar from the fair and which would be allowed.

Bernstein said he changed his mind because he decided Random House "shouldn't be in the position of blocking the free flow of ideas." The publishing house had geared up a major effort for the fair, Bernstein said.

Observers remarked that the cancellation of Bernstein's visa came at a time when the Soviets had been granting them to many formerly barred Americans in an apparent effort to present a friendly and open impression to the world to encourage visitors to the 1980 Olympics games in Moscow and to keep U.S.-Soviet relations on an even keel while the Senate considers the SALT II treaty.

It also surprised observers because it was an ideological move applied to a leading business figure.

"The Soviets have said repeatedly that they want to do business with the West," Bernstein said. "Businessmen should take note, that, with dealing with the Soviets, good faith is not enough."

Bernstein said he had taken two recent actions that might have affected the Soviet decision, although they are consistent with his active promotion of human rights around the world.

On Aug. 1, Bernstein, as president of Helsinki Watch, an organization monitoring abuses of the Helsinki Agreement, held a news conference in New York, attended by prominent Soviet dissidents. The group put through a telephone call to Andrei Sakharov, the dissident physicist and writer who is published by Random House.

Last Wednesday, the day he received his visa, Bernstein granted an interview to a Tass reporter and reiterated his criticism of the Soviets for refusing to allow Sakharov to talk by telephone with his children in Boston and his belief that Moscow should not order trials of Czechoslovakia's Charter 77 dissidents.

The Soviet news agency reporter took out a notebook but took no notes, Bernstein said, causing the publisher to wonder how his opinions were being recorded.

Tass has not published his interview.