Ira Levin's "The Boys From Brazil" outclassed William Goldman's "Marathon Man" in the unofficial best-seller contest to exact imaginary vengeance on the fugitive Nazi death merchant, Dr. Josef Mengele. What held true for the novels goes double for the movies.

Aided by expert collaborators on both sides of the camera, director Franklin J. Shaffiner appears certain to engross a vast moviegoing audience and revive his own sagging reputation with the admirably crafted and surprisingly effective film version of Levin's ingenious chiller opening today at the Academy, K-B Crystal, Uptown and White Flint.

Mengele has earned enduring infamy through accounts of his ruthless genetic experiments with prisoners, especially children and twins, while the chief physician at Auschwitz. Inexplicably unwanted and undetected in the years immediately after World War II, Mengele was eventually forced into hiding. It's believed that he still remains in seclusion and under protection at a hideaway in Paraguay.

Goldman and Levin invented nightmare thrillers in which circumstances forced the evil doctor, thinly disguised as a character named Szell in "Marathon Man" and identified by his real name in "The Boys From Brazil," to venture out in the open, where retribution awaited him at the showdown. Both books catered to pulp heroic fantasies, but Levin proved far and away the more clever and sensible fantasist.

He strengthened his already superior plot by refraining from taking revenge directly through his own stand-in as Goldman did. He has divided that role most astutely between a professional Nazi hunter, obviously inspired by the intrepid, estimable Simon Wiesenthal and called Ezra Lieberman in the film, and a character who stands in the same relationship to Mengele that the monster did to Dr. Frankenstein.

Gregory Peck reveals an unexpected flair for stiff-necked, intimidating villainy in the juicy role of Mengele. Often a righteous bore, Peck seems to have been powerfully stimulated by the opportunity to impersonate a seething, self-righteous moral monster. A severely streamlined makeup job, which includes elongating and thickening his forehead by raising the hairline and lowering the eyebrows, has given Peck a fairly close resemblance to the Mengele one recalls from photos. He enhances the resemblance by suggesting a man whose rigid self-control barely keeps the lid on ferocious vanities ad power drives. Peck has more authority as a menace than I would ever have imagined.

Laurence Olivier, cast as the villain in "Marathon Man," becomes a wonder foil to the villian in "The Boys From Brazil." His frail, mournful, dedicated Liebermann isn't an instantly endearing underdog. Olivier gives him a piping voice that is inclined to grate and whine and a professionally shabby appearance that wouldn't necessarily win friends and influence people. When he collars a Reuter reporter played by Denholm Elliott, you can see why Elliott might have been ducking this supplicant for weeks.

At a meeting in a Paraguay, Mengele activates a murder conspiracy whose aim is to facilitate his master plan for reviving Hitlerism. A free-lance Nazi hunter, a young Jew played by Steve Guttenberg, who made an ingratiating impression earlier this year as the lead in "The Chicken Chronicles," manages to plant a listening device in the meeting room. Before being detected, apprehended and killed by the plotters, he reveals the general outline of the scheme to Liebermann by telephone.

Mengele's plan requires the death of 94 men, all civil servants or petty officials nearing the age of 65, over a span of 2 1/2 years. A team of six assassins is assigned to share Mengele's murderous chores, tracking the victims, who reside in several different countries, and disposing of them as near as possible to predetermined dates.

While the killers proceed to their assignments, Liebermann attempts to verify the fantastic story related to him by his brash, ill-fated young informant. Eventually, his probling edges close enough to the truth to worry Mengele's superiors, represented by a former colonel played by James Mason. Fearing exposure and alienated by his tendency to conceal unpleasant developments, Mengele's superiors decide to terminate the project premanturely. The enraged doctor vows to complete it himself, a decision that ultimately brings him face to face with Liebermann in the home of an intended victim in the Pennsylvania countryside.

Levin contrived to integrate such current topics as cloning and psychohistory into his Gothic calculations, along with the Mengele and Wiesenthal figures (he also worked in Rabbi Meir Kahane, eliminated by the screenwriter) and elements from his previous mysteries, notably the diabolical child motif from "Rosemary's Baby" and the Frankenstein motif from "The Stepford Wives." It's really a snazzy pop entertainment synthesis of accumulating suspense, detective work, pseudoscientific speculation and historical wish fulfillment.

Heywood Gould's screenplay retains the expository deftness and deliberation of the novel while condensing and rearranging things.

He seems exceptionally skilled at finding concise substitutes for rather more involved situations in the novel and at keeping the dialogue crisply informative yet dramatic in obligatory expository scenes. I'm not sure how frequently he rewrites Levin's dialogue or merely paraphrases it, but the screenplay seems unusually conscientious about conveying key bits of information with as much clarity and impact as possible.

All this preliminary expository care no doubt increases the pleasure one derives from the witty finality of the closing sequence between Olivier and John Rubenstein; cast as a young Zionist representing an organization suggested by the Jewish Defense League. Gould and Schaffner have wisely eliminated the cheap kicker Levin permitted himself at the end of the novel.The movie ends on a transcendent note of decency, fusing a simple, lovely fadeout image with a nifty ironic line spoken like a true master by Olivier.

Schaffner's direction may be the smooth and deliberate to release all the visceral fear and loathing stirred up by Levin's crafty story, but it's nevertheless an impressive feat of carefully designed and modulated academic filmmaking, a class job in the tradition of Hitchcock or Wyler at their most polished.

With the exception of some stilted Nazi rigamarole and a discordant scene between Olivier and Rosemary Harris, Schaffner maintains almost exquisite control. His reward - and ours - is a new movie thriller with the virtues of an old-fashioned pip.