Few occasions would seem likely to bring together Alberto R. Gonzales, the Republican attorney general, and one of his Democratic predecessors, Janet Reno. But the party yesterday in the Justice Department's soaring Great Hall was no ordinary event.

Several hundred people from both sides of the aisle gathered to honor and poke fun at David Margolis, the associate deputy attorney general who -- as of yesterday -- has worked at the Justice Department for 40 years under 16 attorneys general.

"Other than a portrait unveiling, I don't know how you would get this many Democrats and Republicans in the same room," joked Paul J. McNulty, the U.S. attorney in Alexandria.

After more than two decades of prosecuting mobsters and other thugs, Margolis has served the last dozen years as an indispensable adviser guiding the debates and decisions of senior department officials from both parties. Chuck Rosenberg, the acting U.S. attorney in Houston who arranged yesterday's fete, called him "the conscience and memory of this institution."

Indeed, in his current post, Margolis has advised a half-dozen deputy attorneys general and played a role in some of the thorniest cases at the Justice Department since the 1990s.

But judging from many of the stories related yesterday, Margolis may be revered nearly as much for his wisecracks and loud ties as his sage legal advice.

According to a news account early in his career, one grizzled cop mistook the young prosecutor for a "draft-card burner" because of his longish hair and mod attire -- the officer changed his opinion after Margolis helped disarm a robbery suspect. Robert S. Mueller III -- a longtime Justice Department official and now director of the FBI -- recalled the first time he met Margolis, who was wearing cowboy boots, a Western-style shirt, jeans, dark glasses, an oversized belt buckle and "a haircut from the movie 'Dumb and Dumber.' "

Mueller and almost everyone else who has worked with Margolis also inevitably bring up his legendarily cluttered office, which includes Elvis memorabilia, Yankees merchandise, news clippings and photographs of government officials.

Mueller said the photographs serve as an uncanny barometer of the political climate: pictures of Margolis with prominent Democrats during a Democratic administration, pictures of Margolis with prominent Republicans during a GOP ascendancy and equal numbers of each as a campaign season approaches.

"As it gets closer," Mueller said dryly, "you will see who he thinks is going to win."

But seriously, Democrats and Republicans said yesterday, Margolis plays it straight with political appointees from either party.

"If you're full of crap, Margolis will tell you you're full of crap," said James B. Comey, the departing deputy attorney general. "He'll tell that to me, he'll tell that to the attorney general, he'll tell that to anybody."

Despite four decades on the job, Margolis, now 65, has no immediate plans to retire. Although the party was supposed to be a surprise, Margolis said officials ended up telling him about it 10 minutes early.

"They were afraid I'd drop dead of a heart attack and my estate would sue the department," he said with a laugh.

Margolis, left, the "conscience" of Justice, and FBI chief Robert S. Mueller III.

David Margolis, a 40-year Justice Department lawyer, hugs William Lynch at party.