At the FBI Academy in Quantico, Virginia, a guidance drummed into the heads of new agents is, “Don’t do anything to embarrass the bureau.”

Former agents say it is an appropriate lesson to maintain the G-men’s straight-arrow standards. It also is an indication of how the FBI hierarchy is committed to guarding its reputation as the world’s greatest law enforcement body.

The great lengths that FBI Director Christopher A. Wray took last month to keep secret a four-page memo on his bureau’s Russia-Trump probe do not mark the first time headquarters sought to block Congress — and protect its image.

The FBI’s recent history is checkered by episodes of stonewalling, whether the storyline focused on a spy in its midst, corrupt crime labs or the persecution of a war-hero senator.

Democrats have rallied behind the FBI as Rep. Devin Nunes, California Republican and chairman of the House Permanent Select Committee on Intelligence, issued the memo that accused the bureau of exploiting a Democrat-funded, unverified dossier to target Donald Trump as a presidential candidate.

But sometimes the FBI’s scandals are too much for Democrats, too. In 2001, after a series of FBI mistakes, Sen. Patrick J. Leahy, Vermont Democrat, said, “Its much-vaunted independence has been transformed for some into an image of insular arrogance.”

Mr. Nunes nearly single-handedly has led the probe into FBI misconduct. He openly accused the FBI of blocking his inquiry and asked in a letter who would investigate the investigators.

Mr. Nunes eventually dug up embarrassing facts about the FBI, such as its use of a discredited, Kremlin-sourced dossier and falling for the lies of its author, former British intelligence officer Christopher Steele.

The 7th Floor, as the FBI chieftains are pegged at the Hoover Building, has put up other barricades over the years.

The FBI resisted congressional inquiries into one of its biggest scandals: false evidence and trial testimony ginned up inside its vaunted forensic crime laboratories.

The FBI bungled an investigation into one of its own and America’s most damaging spy ever: agent Robert Philip Hanssen. Other agents could not believe a graduate of Quantico, a brother in a storied fraternity, would violate the creed “Don’t do anything to embarrass the bureau.”

For years, counterintelligence agents hounded the wrong guy — an innocent CIA analyst outside the bureau. Agents even sent a fake Soviet operative to his front door to promise a quick getaway to Russia.

The FBI misled the Justice Department and itself.

“Hanssen was the most damaging spy in FBI history, and he betrayed some of this nation’s most important counterintelligence and military secrets, including the identities of dozens of human assets, at least three of whom were executed,” said a 2003 Justice Department inspector general report issued two years after his arrest.

The report told of a near-willingness to look the other way. The FBI knew for years that a mole was deep inside U.S. intelligence. Hanssen violated security protocols several times. He even broke into a colleague’s computer.

Yet the IG found: “The FBI never opened even a preliminary inquiry on any FBI employee in connection with the search for the mole ultimately identified as Hanssen. This was true even though the FBI had access to information suggesting that the mole might be an FBI employee, and believed that the mole had compromised certain FBI assets and operations.”

More damning: “Most importantly, the FBI demonstrated a reluctance to consider itself as a possible source for a penetration in the absence of leads identifying a specific FBI target. Thus, the FBI maintained a focus on the CIA as the mole’s employer despite information indicating that the mole might be an FBI employee.”

Worse, when agents were hounding the innocent CIA suspect, the bureau misled the Justice Department criminal division.

“Because the FBI did not provide the Justice Department with complete information about its investigation — omitting crucial information about weaknesses in proof and investigative setbacks — the Justice Department could not properly evaluate the strength of the FBI’s case against the CIA suspect,” the IG said.

The FBI went through a number of scandals in the 1990s and early 2000s. It was Sen. Chuck Grassley, Iowa Republican and now the Senate Judiciary Committee chairman, who led the call for reforms just like he is today in the bureau’s dossier scandal.

“We must change the FBI culture that has caused these colossal mistakes,” Mr. Grassley said in 2001. “I want to know that the next FBI director is committed to sweeping changes.”

‘Flawed testimony’

The hiccups back then: concealing documents from defense attorneys for Oklahoma City bomber Timothy McVeigh, wrongly accusing a man of the 1996 Atlanta Olympics bombing and fumbling an investigation into Chinese espionage.

Fox News quoted Kris Kolesnik, then director of the National Whistleblower Center, as saying, “The culture is driven by image. Don’t embarrass the bureau. Make the bureau look good.”

This rocky era for the FBI served as the entree for Senate Judiciary Committee investigations and public hearings.

One theme: The FBI hid its mistakes.

“The FBI has long been considered a crown jewel of law enforcement agencies,” Mr. Leahy said during a summer 2001 hearing. “Unfortunately, today it has lost a lot of its earlier luster. Unfortunately, the image of the FBI in the minds of too many Americans is that this agency has become unmanageable, unaccountable and unreliable.”

The senator said his investigation into crime lab failings found “institutional arrogance.” The lab told outside investigators how to conduct forensic tests but would not take advice from them.

However, when the Nunes memo showed that the FBI had used an unverified partisan dossier to wiretap Trump volunteer Carter Page, Mr. Leahy defended the bureau. “The FBI did its job. Rank-and-file national security professionals within the FBI and DOJ acted appropriately when obtaining a FISA warrant of Carter Page,” he said.

Michael R. Bromwich, then the Justice Department inspector general, testified that when FBI lab employees reported failings in test procedures, “They were ignored. They were swept under the rug, and the problem became far worse. … It became really a cancer in the lab.”

According to The Washington Post, it was not until more than 10 years later that the FBI completely fessed up.

“The Justice Department and FBI have formally acknowledged that nearly every examiner in an elite FBI forensic unit gave flawed testimony in almost all trials in which they offered evidence against criminal defendants over more than a two-decade period before 2000,” said an April 2015 article in The Post.

Years after the Leahy hearings, the Department of Justice began releasing documents in the FBI’s intense investigation into the Enron scandal in the early 2000s.

Sidney Powell, an appeals lawyer, had pressed for the long-hidden papers that showed Justice Department prosecutors had withheld exculpatory evidence that would have helped defendants.

She also said defense attorneys found altered and destroyed 302 Forms, which agents use to memorialize interviews with witnesses. But it was difficult to find out who in the FBI did these deeds.

“Every time a court finds government misconduct in any fashion, they asked to have names removed. Courts often comply,” Ms. Powell told The Washington Times.

Ted Stevens and Judicial Watch

Then there was the prosecution of Sen. Ted Stevens, Alaska Republican and World War II aviator hero. The Justice Department gained a 2008 conviction by portraying a cabin remodeling job as a bribe for Stevens favors.

U.S. District Judge Emmet G. Sullivan in Washington threw out the conviction after an investigation showed that the Justice Department withheld evidence from the defense.

An FBI agent, Chad Joy, had the courage to file a whistleblower complaint against one of the bureau’s own. His co-investigator, Mary Beth Kepner, concealed evidence favorable to Stevens, poorly documented interviews and leaked grand jury testimony to the press. The Stevens defense team said she also had an inappropriate relationship with a witness.

Then-FBI Director James B. Comey told Congress in 2014 that Ms. Kepner had been disciplined.

The FBI misconduct would likely have remained a secret without Mr. Joy.

Tom Fitton, president of the conservative government watchdog group Judicial Watch, has peppered the FBI with Freedom of Information Act demands — and often been turned down.

In one instance, Mr. Fitton asked the FBI for any material on the infamous airport tarmac meeting between Attorney General Loretta E. Lynch and former President Bill Clinton. At the time, Hillary Clinton was under FBI investigation for using a private at-home email server to conduct State Department business and relay classified information.

The FBI told Mr. Fitton that it had nothing to deliver. Then the Justice Department complied with his request and turned over FBI emails on the June 26, 2016, meeting.

“The FBI is out of control. It is stunning that the FBI ‘found’ these Clinton-Lynch tarmac records only after we caught the agency hiding them in another lawsuit,” Mr. Fitton said in an October statement.

“The FBI leadership is arrogant, secretive and contemptuous of the rule of law,” he told The Times

Robert Mueller, now the special counsel looking into suspected Trump-Russia collusion, became FBI director in September 2001 and suffered through some of bureau’s scandals before completing his tenure in 2013.

At a college speaking engagement in March 2017, The Herald Bulletin in Indiana reported, he told students, “For the bureau, one of the most important things is integrity.”