BOSTON — A former top henchman of Boston mob boss James “Whitey” Bulger testified on Wednesday on how a corrupt FBI agent helped them avoid indictments on charges of fixing horse races, a case that snared other Boston mobsters in 1979.

Stephen “The Rifleman” Flemmi testified that corrupt FBI agent John Connolly persuaded the federal prosecutor to make sure he and Bulger were not prosecuted so they could keep providing the FBI with information on rival gangs.

“Jim Bulger and myself were taken out of the indictment. That’s what John Connolly told me and that’s what Jim Bulger told me,” Flemmi said.

Fellow gang member Howard Winter was arrested in that sweep, convicted and spent 10 years in prison, Flemmi testified, while he and Bulger remained continued their crimes with the FBI’s knowledge.

Connolly, like Bulger an Irish-American from South Boston, turned a blind eye to the gang leader’s crimes in exchange for information on the Italian Mafia, a top FBI target at the time.

Connolly is now serving a 40 year prison sentence on murder and racketeering convictions.

Bulger has denied serving as an informant, insisting through attorneys that he paid Connolly for tips but provided none of his own. This is the seventh week of his trial on charges related to 19 murders he is accused of committing or ordering in the 1970s and ’80s while running Boston’s Winter Hill crime gang.

The 83-year-old defendant, whose story inspired Martin Scorsese’s 2006 Academy Award-winning film “The Departed”, has pleaded not guilty to all charges, though his lawyer admitted Bulger had been a drug dealer, extortionist and loan shark — in other words “an organized criminal.”

Defense attorneys have tried to undermine the credibility of prosecution witnesses who were former members of Bulger’s gang, arguing that they fingered Bulger for killings in exchange for shorter prison terms for their own crimes.

Flemmi is an exception since he is the one top Bulger lieutenant still in prison, serving a life term for 10 murders he confessed to a decade ago.

The trial has brought jurors back to a different era in Boston history, when Bulger’s gang acted with impunity. Some of the murders described took place just blocks from the waterfront site that today is home to Boston’s federal courthouse.

Bulger fled Boston after a 1994 tip from Connolly that arrest was imminent. He spent 16 years in hiding, evading capture even while on the FBI’s “Most Wanted” list. Agents arrested him in June 2011 in a seaside Santa Monica, California home where he lived, keeping a cache of guns and $800,000 cash.