This nation's first international book fair ended today with the American publishers, who arrived last week worried about costs and censorship, wreathed in smiles over their crowds, their contacts - and their profits.

The crowds totaled about 140,000, according to Soviet officials: those publishers who cared saw whomever they chose of dissident writers: and they did far more business than they had anticipated.

"On balance, we are happy," said Winthrop Knowlton, president of Harper and Row, the big New York publishing house, who has functioned as a spokesman for a number of the American publishers here. His firm has published Alexander Solzhenitsyn and other dissenting authors who are banned and sometimes vilified here.

At the same time, Knowlton acknowledged serious, continuing differences with the Soviets on key issues of government censorship and suppression of nonconforming writers, profound matters of freedom of speech that are part of the controversies that divide the Soviet Union and the United States.

But he stressed that "quite a lot a good news" came from the fair from his point of view, and said he is confident that the future holds promise of more exchanges, more Western books for an avid Soviet readership and more business for the publishing houses of the West.

For the general public, the fair closed yesterday, and people flocked to the exhibits despite the pelting rain squalls that raced across the Moscow skyline, buffeting pedestrians and whipping the last brilliant flowers of summer in their garden plots.

The two halls of the fair were filled with crushing crowds and long lines and alive with an almost frantic intensity among the people to see, feel, and perhaps acquire a book, a pamphlet or any souvenir from the unique event.

As the rain beat against the vast glass windows of the exhibit halls, a huge line of densely packed Soviet citizens formed at the information booth just inside the doors, waiting patiently for brochures that described the general layout and daily events of the fair, which was within an hour of closing.

Outside, the rain fell intermittently on hundreds of leather valises, briefcases and shopping bags that the police compelled fairgoers to outside, the ease the job of catching pilferers.

According to figures compiled by the publishers, U.S. firms sold 75 translations to their Soviet counterparts and bought 39 in return. The leaders apparently were the Times-Mirror Co. of Los Angeles, which sold about $300,000 worth of book rights; followed by Prentice-Hall International Inc., which sold about $160,000 in rights, chiefly in scientific and educational books. The Americans also signed about 2,000 options, which could mean many thousands of dollars more if the Soviets act on them.

The Soviet copyright agency, known as VAAP, last year bought about $1.9 million in the United States and sold about $700,000, according to the Americans. The Soviet Union now runs a trade deficit of several billion dollars in the West, and the publishers reported that Soviet officials here seem eager to buy more but have no more money to do so than in 1976.

Soviet book agencies also bought outright the entire display stocks of the U.S. publishers for their own libraries. The sole U.S. display that was not bought was the American Jewish Publishers' Association, which showed about 200 titles in English and Hebrew. That display, like the one of Israeli publishers, was thronged from the first day - and closely watched by security police.

Altogether about 1,300 publishers from some 60 countries were represented, a much smaller number than usually turn out for international book fairs. Some American firms stayed away because of the imminence of next month's major European exhibit, the Frankfurt fair. Others kept away because they did not want to participate in a fair run by a government that suppresses such dissident writers as Lev Kopelev, Vladimir Voinovitch and Alexander Zinoviev. At a New York meeting last month, the American companies coming here were urged by several other publishers to show publicly their support for the writers and for such jailed human-rights activitists as Anatoly Scharansky, who reportedly has been charged with treason.

A number of publishers met with dissidents, many of whom came openly to the fair and had no difficulties. But several American publishers, including Knowlton and Leo Albert of Prentice-Hall expressed worry that conditions could worsen for the dissidents once the Americans have gone home.

Other Americans worried that the Soviet show of openness and non-interference is just that, a show, put on for the benefit of next month's Belgrade conference of nations that signed the 1975 Helsinki accords on European security. The conference will assess the signatories' compliance with human-rights provisions.

Knowlton, who sharply criticized the Soviets last week for seizing 10 books, including "Animal Farm" and "1984," said today that censorship had turned out to be "less than we expected." Carl Proffer, whose Ardis Publishers specializes in Russian writers, said he was "quite pleased" at what he said was lack of censorship of his booth, which included titles by Vladimir Nabokov, Anna Akhmatova, Joseph Brodsky, Boris Pasternak, Nadhezhdya Mandelstam and others whose works are either seen here seldom or banned outright.

The United States and the Soviets will further discuss a protocol the Soviets want that would set forth the official relationships between publishers of the two countries. At present, negotiations are stalled on wording concerning censorship. Talks also will continue about setting up a permanent store or exhibit for American books in Moscow.