This June 3, 2013 file courtroom sketch depicts James "Whitey" Bulger, center, during a pretrial conference before U.S. District Judge Denise Casper, left rear, in a federal courtroom in Boston. Bulger is flanked by his attorneys Henry Brennan, left, and J.W. Carney Jr., standing at right. (Jane Flavell Collins/AP)

A former Massachusetts State Police investigator who doggedly pursued James “Whitey” Bulger testified Thursday that his efforts to bust the longtime Irish mob boss and other organized-crime figures were disrupted by FBI agents and Justice Department officials.

Thomas Foley, who rose to superintendent of the state police, said wiretaps were blown, suspects were tipped off and damaging leaks slipped out from federal law enforcement officials who were supposed to pursue local mobsters.

Bulger, accused of 19 murders, was helped by corrupt FBI agents who looked the other way in exchange for his tips about the local Mafia, according to a federal judge’s ruling and various investigations.

Although Foley acknowledged being “naive on some things” at first, he said a “pattern started to develop that we thought was unusual.” Asked by defense attorney Hank Brennan whether he was surprised to eventually learn that other law enforcement officials, including FBI agents, were undercutting him, Foley had a terse answer: “Yes.”

Foley’s criticisms of federal law enforcement came on cross-examination by Bulger’s defense team, which has tried to argue that Bul­ger, the menacing former boss of the Winter Hill Gang, had been given immunity for his crimes by federal officials. U.S. District Judge Denise J. Casper has ruled such a defense is not admissible.

Bulger has mystified prosecutors by contending that he was not an FBI informant. He deplores snitches, his attorneys say, especially because of how they are viewed in Irish culture. To gain favor, Bulger simply paid off FBI agents and police officers, defense attorneys say.

The defense strategy, so far, has been to paint federal officials as corrupt whenever possible. How that helps Bulger defend himself against the 32 charges he faces is unclear, unless the goal is to discredit and embarrass the FBI and Justice Department, a tactic some longtime Bulger watchers had predicted.

During the testimony of Robert Long, another former state police investigator, defense attorney J.W. Carney Jr. asked whether a senior official in the U.S. attorney’s office in Boston had been made aware of an important wiretapping operation. Long said yes. Asked how soon the wiretap was compromised, Long replied, “Within days.”

But it was Foley’s testimony that was most embarrassing to federal law enforcement.

Brennan called attention to Foley’s 2012 book, “Most Wanted: Pursuing Whitey Bulger, the Murderous Mob Chief the FBI Secretly Protected,” particularly this passage: “The feds stymied our investigation of Whitey, got us investigated on bogus claims, tried to push me off the case, got me banished to a distant barracks, phonied up charges against other members of the State Police, lied to reporters, misled Congress, drew in the president of the United States to save themselves, nearly got me and my investigators killed.”

Brennan got Foley to confirm those assertions on the stand. And on redirect examination, prosecutor Fred Wyshak asked Foley whether the FBI’s informant program was poorly managed. “To say the least, it was poorly run,” Foley replied.

Earlier in the day, jurors sat in rapt attention as Foley held several machine guns that he had seized from some of Bulger’s accomplices and hangouts. Foley conceded on cross-examination that Bulger’s fingerprints weren’t on the weapons.

Jurors also saw photos of places where guns had been hidden behind fake walls and of seized evidence that included boxes of ammunition, Halloween-style masks, derringer pistols, silencers, brass knuckles, and double-edged knives — the tools of the gangster trade.

There was also testimony about how Bulger and his crew allegedly made money, including bookmaking, loan-sharking, drug dealing and extortion. If businesses or bookmakers wanted to operate on Bulger’s turf, they had to make “rent” payments, Foley testified.

Foley was asked about the consequences of nonpayment. “It could range from being put out of business to taking a beating,” he said. “Or actually, at some times, people were killed.”