David Margolis, an associate deputy U.S. attorney general who has been with Justice Department for 50 years, has worked on some of the department’s most politically controversial issues in past 25 years. (Photo by Katherine Frey/The Washington Post)

David Margolis can still recall the thrill he felt almost 50 years ago. A newly minted federal prosecutor, he stood in the U.S. District Court in Hartford, Conn., and said these words: “Your Honor, this is David Margolis, and I’m representing the United States.”

And he can still recall the sting of the response.

“Now just remember, counselor,” the judge told the young and perhaps a bit arrogant assistant U.S. attorney. “You represent the United States. You’re not the United States yourself.”

That admonition, said the now-75-year-old Margolis, has stuck in his mind. It has been a reminder that no matter how high he rose, he should never get too big for his bell-bottoms. (More on that later.)

Margolis recently completed 50 years at the Justice Department, an occasion marked last month by a ceremony — part tribute, part roast — in the Great Hall. There were remarks by Attorney General Loretta E. Lynch, who had been sworn in that day — and hundreds of officials and former officials were in attendance.

In a photograph from the early 1970's, David Margolis, right, and colleague Marvin Loewy pose with tommy guns in Cleveland. The photograph is in Margolis’s office at the Department of Justice.

Margolis is the senior-most career employee in the department and one whose tenure out-clocks that of J. Edgar Hoover, the legendary FBI director. A tall, shambling bear of a man, Margolis has been the consigliere to a succession of deputy attorneys general, with a Forrest Gump-like knack to be involved with a number of the most politically controversial issues of the department’s past 25 years.

Despite his somewhat lofty status as an associate deputy attorney general in the stately granite-and-marble Justice Department building, he disarms people with his disregard for appearances — an occasional shirttail hanging out, food stains on his tie — and with his mastery of the spontaneous quip.

On one occasion, Margolis, who was sometimes called to testify on the Hill, was asked by a lawmaker how many people work at the Justice Department. “About 60 percent,” he said, without missing a beat.

On another occasion, he was called to testify before the Senate Whitewater Committee, which was investigating Vincent Foster’s suicide. He was still recovering from a heart attack and quadruple-bypass surgery, and the committee’s Democratic counsel, aware of that, asked, “Mr. Margolis, are you comfortable?”

“No,” he said. “But I make a living.”

Margolis’s fourth-floor office is a gallery of mementos and eBay paraphernalia. The walls covered with framed photos of him with a succession of attorneys general and an Elvis Presley clock. Baseballs signed by New York Yankees — Mickey Mantle and Casey Stengel among them — are heaped in a jar on a side table. Bottles of ant­acid sit on his desk.

Today he wears his graying hair short, but for decades he was a sartorial iconoclast. In the 1960s and ’70s, when he was a young prosecutor and rose to chief of the Organized Crime and Racketeering Section, he sported long hair and sideburns, bell-bottoms, and belt buckles the size of cantaloupes.

James Cole, who was deputy attorney general from 2011 until January, described the first time he saw Margolis in 1979. As Cole entered the building one morning, “in front of me is a guy with hair down to his shoulders, cowboy boots, a pink leisure suit and nicotine stains on his fingers,” he recalled. “I’m thinking, ‘They’re never going to let him in.’ And it was Dave. Head of the organized-crime section.”

Margolis was born in 1939 in Hartford. His father worked for the city board of education and was a Democratic ward chairman. His mother taught school in Hartford.

Margolis, who despite the Marlboro-smoking rebel image he cultivated as a youth nonetheless studied hard and graduated cum laude from Brown University. He graduated from Harvard Law School in 1964, thinking he would become a criminal-defense lawyer. But some friends got him a job interview with the U.S. attorney in Hartford. “I told him I wanted to be a defense attorney so I could protect the rights of the accused,” he recalled. And the prosecutor said something that struck him: “that the prosecutor really has great say in how the defendants’ rights are protected because prosecutors decide who gets charged.”

He became an assistant U.S. attorney. Only four years into the job, he single-handedly coaxed an armed robber into surrendering rather than engage in a shootout with police. Walter P. “Tippy” Doolittle, wanted on bank-robbery charges, agreed to turn himself in after 50 minutes of “heated” discussion with Margolis, according to a framed front-page article in the Hartford Courant, hanging on his office wall. The article also noted that Margolis made the arrest “while attired in an Edwardian suit.” (It was blue.)

He rose quickly. He joined the department’s organized-crime section, first with the Boston Strike Force, then Cleveland, then Brooklyn. By 1976, he became deputy chief of the Organized Crime and Racketeering Section and moved to Washington. And in 1979, he was named chief.

In his 11 years in that job, the section rocked. “We really brought the mob to its knees all over the country,” he said.

Using wiretaps, undercover operations and the RICO statute, which enabled prosecutors to charge members of a mafia group with different crimes in one indictment, prosecutors and agents took down bosses, underbosses and consiglieri in cities ranging from New York, Chicago and Boston to Cleveland, Detroit and Philadelphia. Anthony “Fat Tony” Salerno. Carlos “The Little Man” Marcello. Carmine Persico. All were convicted and given long sentences.

In 1993, he was named associate deputy attorney general. He worked for the deputy attorney general, essentially the chief operating officer of the department. “We would give all the hairballs to [Margolis], all the hardest, most difficult problems, the most politically controversial,” recalled FBI Director James B. Comey, a former deputy attorney general.

Vince Foster’s suicide. Ted Stevens’s botched prosecution for public corruption. The leak of Valerie Plame’s identity. The firings of U.S. attorneys. Margolis was involved — in some way — in them all.

Undoubtedly the most controversial issue he has dealt with came in the early years of the Obama administration. The department’s internal watchdog, the Office of Professional Responsibility, had determined that former Office of Legal Counsel lawyers John Yoo and Jay Bybee had engaged in professional misconduct in writing two memos that gave legal sanction to the use of torture tactics such as waterboarding, as well as wall slamming, extended sleep deprivation and other extreme techniques used by the CIA to interrogate terrorist detainees. Margolis had to decide whether to endorse the OPR’s recommendation that the two lawyers from the Bush administration, who by then had left government, be disciplined.

That was the decision “I agonized over most,” he said. “I knew it would be controversial whichever way it came down.”

In a memo written in January 2010, he conceded that “Yoo’s loyalty to his own ideology and convictions clouded his view” of his professional obligation. But, he concluded, Yoo did not “knowingly” provide inaccurate legal advice and he overturned the OPR recommendation.

That set off a firestorm of criticism from Democratic lawmakers, civil liberties advocates and human rights activists.

“I don’t want to accuse him of bad faith,” said David Luban, a Georgetown University Law Center professor of law and philosophy. “But I will accuse him of bad reasoning.”

Cole, the former deputy attorney general, said Margolis’s decision was “a very tough call. I may not agree with it, but I’m sure it was a good-faith effort to interpret a very difficult area of the law.”

There is another attorney who served at the Justice Department longer than Margolis has: his onetime mentor, Jack Keeney, who retired in 2010 after a 60-year run.

On his last day in office, Keeney asked Margolis to accompany him to the exit. As they walked down the hall, doors were flung open and the applause was almost deafening. “Jack, listen to that applause for you,” Margolis said. “They must think,” Keeney replied, “that I am taking you with me.”

Margolis initially said in an interview that he does not want to break Keeney’s streak. “He’s my dear friend. I want him to have his record,” he said. “I’m going to stop one day short.”

Then he paused to reflect on what that would mean. “I say that now,” he said. “But when the time comes, I’ll say, ‘What the hell, I’ll stay.’ ”