The Moscow book fair, one of the few remaining offshoots of detente, closed today after providing opportunities for thousands of Russians to have some contact with the United States despite the tense state of relations between the two governments.

But among the books that Russians, hungry for contact with the outside world, were unable to see was former president Jimmy Carter's memoirs, confiscated by customs officials along with many other books scheduled to be shown at the fair.

About 50 fringe publishers represented the Americans at the Fourth Moscow International Book Fair. They were invited--some would say pressganged--by the Soviets to attend because the big name publishers refused to take part.

Ever since the first Moscow book fair was held in 1977, the event has created controversy among western publishers. Many have insisted that it should be boycotted because of Soviet censorship practices and harassment of independent writers. Others believe it is important to exploit any channel of communication with the Soviets, even if it means accepting rules laid down by Moscow.

The dilemma has been particularly acute this year as the opening of the book fair coincided with the outcry in the West over the Soviet destruction of a South Korean jumbo jet with 269 persons on board. More western books than ever before were confiscated by the censors and a planned satellite hookup between the book fair and the University of California campus had to be canceled because of the plane tragedy.

A tour around the book fair before it closed provided an insight into the rewards and frustrations of trying to do business with the Russians at a time of international crisis. It included glimpses of hundreds of Russians waiting patiently for hours to get into the Israeli exhibit, a huge crowd around a 1910 Russian language Bible brought over from the United States and dozens of taciturn security men frisking visitors for stolen books.

Perhaps symbolically, the tour ended with this correspondent being temporarily detained by two plainclothes police officers for taking notes about some of the western books on display.

The tour began at the stand of Book People, who described themselves as the largest distributor of small publishing houses in the United States. They are into subjects like holistic health, appropriate technology and eastern spiritual disciplines. So too, it seemed--judging from the long line of people waiting to get a peek at their books--are Russians.

Wendy Grace, the Book People representative, explained that at least 200 of the 700 books they brought from Berkeley, Calif., "disappeared" in the first two days of the fair. The Soviet deputy director consoled them with the thought that the statistic was a fair measure of public interest ("You're lucky, some stands don't lose any books at all"), but after that they started taking stricter precautions.

Asked whether attending the Moscow book fair was morally justified in view of the shooting down of the plane, Grace replied: "There's a lot of controversy surrounding exactly what happened. We think we have to go on cooperating and communicating with the Russians and not allow ourselves to get dragged down the dead end of cutting all dialogue off altogether. That way, we'd just become political pawns."

She said that Book People hope to at least break even on the Moscow book fair, but their main purpose is to reach people in the Soviet Union.

"It's funny, but there's a completely different attitude to books here than back home. Russians seem to love books; I mean really love them. There is such a glut in the West, with books being remaindered in the thousands, that we tend to take them for granted. But here they're really appreciated because they are so difficult to come by," Grace said.

A young Russian who identified himself only as Sasha was trying to read a volume of Carl Jung's psychology with the help of an English-Russian dictionary. He said he had to wait two hours just to get into the pavilion but it was worth it, "because this kind of book is practically impossible to find here."

The fact that the Moscow book fair is boycotted by most of the big American publishers means that the Russians are eager to attract smaller publishers like Book People. In the past, this has had a spinoff effect of allowing unorthodox cults and religious sects to creep in under the Iron Curtain.

Perhaps the best known example is the Hare Krishna sect that infiltrated the Soviet Union in 1979 by getting its publishing arm to open a stand at a previous book fair here. The movement snowballed and it took the Kremlin some time to catch up on what was happening, sources here said. Last year they finally cracked down, arresting Krishna converts on charges of "parasitism" as far away as Siberia.

Joseph Goldin, a Russian writer who was helping out at the Book People stand, said that Russians are strongly attracted to the self-improvement fad that is sweeping the United States.

"In that respect, at least, we are very much alike," he said.

Asked about the row between Moscow and Washington over the Korean airliner, he replied: "What this episode proves is that people died because of lack of communication. If we talk to each other directly, there'd be less chance of a small crisis like this being repeated on a larger scale."

Over at the Association of Jewish Book Publishers' exhibit, Sol Scharfstein was fuming. Forty-nine of his 2,000 books had been seized by the censors.

Most of the books that were confiscated concerned Jewish history. But the list included "Keeping Faith" by Jimmy Carter, which Scharfstein said he brought along to read rather than to exhibit. He joked that when he gets back to New York, he will buy stock in Bantam Books, Carter's publisher.

"The Carter book never did really well when it first came out. Now it's been banned in Moscow; I guess it will take off," he said.

Dealing with the Russians on an official level, Scharfstein said, demands toughness and strong nerves.

"Back home, I carry out the garbage and get beaten by my wife twice a day. Over here I become a tiger, a lion of Judah. You can't show fear," he said.

Asked about the boycott, he said he could understand why big publishers like Random House don't want to come to Moscow. But, he added: "America is a pluralistic society. We don't march in goose step. Our way of combating the problems here is to come and face the challenge, to try and open the door a little wider."

Through the book fair, the Jewish Publishers' Association has been able to distribute 10,000 copies of a catalogue that includes information about the Jewish faith, a Jewish calendar and a prayer. When he visited the Moscow synagogue last week, Scharfstein said he was moved to see someone praying with the help of the 1981 catalogue.

The constant crush around the American Jewish exhibit was nothing, however, to the crowd outside the Israeli stand. This was perhaps the most remarkable exhibit in view of the fact that there are no diplomatic relations between the Soviet Union and Israel. Some Soviet Jews spent hours there leafing through picture books about Israel or just imbibing the atmosphere.

Jacob Levinger of the Israel Export Institute estimated that he had distributed 50,000 free catalogues during the week of the fair. Some of the catalogues were confiscated by the phalanx of police guarding the exit doors, but most found their way into people's homes to be treasured as mementos.

At the American Protestant stand, Clyde E. Weaver of the Brethren Press kept constant guard over what he said was the most looked at book in the entire fair: one of 10 handmade copies of a Russian Bible that was taken to America before the Bolshevik revolution. Old women, soldiers in uniform and children peered in amazement at its beautifully inscribed pages. Nearby, two security men controlled the crowd, letting people into the exhibit in small groups. Their presence was a kind of intimidation but they did not interfere with readers as they browsed through the religious books on display at the Protestant stand.

Around the corner, an exhibition of books by Karl Marx in a dozen languages was deserted. There were no crowds, no security men. It would have been easy to steal the books, but no one bothered.