Farley Mowat, the Canadian author and naturalist, two years ago sought to come into the United States. His purpose was to promote a book he had just published, but customs officials in Toronto turned him back. How come? Mowat's name was in the ''lookout book.''

The pleasant news is that Mowat now can come in whenever he wishes. Thanks largely to New York's Sen. Daniel Patrick Moynihan, Congress has effectively repealed the most stupid and un-American provisions of the old McCarran-Walters Act. We are rid of a national embarrassment.

Mowat's problem was that nearly 20 years ago the U.S. attorney general had cited him under Paragraphs 27 and 28 of Section 212A of the Immigration Act. The provisions bar admission of aliens who might be coming here ''to engage in activities which would be prejudicial to the public interest, or endanger the welfare, safety or security of the United States.'' The sections cover anarchists, communists and assorted revolutionaries with bad ideas.

What had Farley Mowat done to deserve a blacklisting? It transpired that in 1968, in a moment of puckish humor, he had formed the ''Newfoundland Revolutionary Society.'' It consisted of three members whose publicly avowed purpose was to steal an atom bomb, deposit it in a Canadian lake and then fire shotguns at any U.S. plane that came near. This was intended as satire, in the fashion of ''The Mouse That Roared,'' but the U.S. Department of Justice had no sense of humor. Membership in this sinister society, along with Mowat's reputation as a radical pacifist, was enough to get him in the lookout book.

There he had plenty of company. Over the past 35 years, Paragraphs 27 and 28 have been invoked to protect the United States from all kinds of opinions. We have denied entry to such political infidels as Ian Smith, former prime minister of Rhodesia; Bernadette Devlin, a radical member of the British Parliament; the Rev. Ian Paisley, a notorious Protestant bigot; Graham Greene, the English novelist; Oscar Niemeyer, a Brazilian architect; and scores of poets, sociologists, students, priests and scholars.

Moynihan's quiet achievement a couple of weeks ago was to insert a sentence into the State Department authorization bill: ''Notwithstanding any other provision of law, no alien may be denied a visa or excluded from admission into the United States . . . because of any past, current or expected beliefs, statements or associations which, if engaged in by a United States citizen in the United States, would be protected under the Constitution of the United States.''

That does it. In today's atmosphere of de'tente and ''glasnost,'' it is difficult to remember the poisonous fears that hung over our society in 1952. This was the heyday of Sen. Joe McCarthy of Wisconsin, who made political capital of the anticommunist hysteria of the time. Yes, of course the Soviets were then engaged in espionage -- the Soviets always are engaged in espionage -- but there never was justification for the sweeping provisions of the McCarran-Walters Act. Harry Truman vetoed it, but a paranoid Congress passed the law anyhow. Since then, as Moynihan told the Senate, capricious enforcement of the law has made martyrs of left-wingers around the world. The act has made a mockery of our most vaunted freedom -- the freedom to express ideas.

Moynihan's amendment was part of a comprehensive bill authorizing $4.1 billion for the conduct of foreign relations in fiscal '88 and '89. When the bill came before the Senate in September, members had a larky time with it. They encumbered the measure with more than a hundred amendments intended to put the State Department in its place. A conference committee scraped away most of these political barnacles, and the final bill proved acceptable all around.

Thus agreement was reached in true diplomatic fashion on a number of touchy issues. The bill does not require the United States to build an embassy in Israel in Jerusalem; the bill merely forbids the building of a new embassy anywhere else. The bill does not exactly oust the Palestine Liberation Organization from its mission in New York; it only implies this. The bill does not demand compensation from Japan's Toshiba corporation for selling strategic machinery to the Soviets; the bill simply ''initiates a process'' toward that end. Nothing positive is done about our bugged embassy in Moscow or the Soviets' advantageously located embassy in Washington.

All in all, not a good bill, but not a bad one. Moynihan's excellent amendment alone would justify Reagan's okay.