A former FBI agent pleaded guilty Monday to lying repeatedly during his testimony at the trial of Boston gangster James "Whitey" Bulger, including claiming he was the first officer to recover the gun used to assassinate Martin Luther King Jr. in 1968.

Robert Fitzpatrick, 76, was accused of lying to jurors and overstating his professional accomplishments during Bulger's 2013 racketeering trial. He pleaded guilty in federal court to six counts each of perjury and obstruction of justice.

Fitzpatrick, who had been an assistant special agent in charge of the FBI's Boston division during Bulger's bloody reign, was the first witness Bulger's lawyers called during the high-profile trial.

At a hearing Monday, Assistant U.S. Attorney Zachary Hafer said Fitzpatrick lied on the witness stand "in order to enhance his own credibility" and to bolster Bulger's defense.

Hafer said Fitzpatrick lied when he portrayed himself as a "whistleblower" who tried to end the Boston FBI's corrupt relationship with Bulger. Bulger worked as a criminal informant for the FBI at the same time he led a violent gang responsible for numerous murders.

Hafer said if the case against Fitzpatrick had gone to trial, prosecutors would have presented evidence that Fitzpatrick actually "thwarted" efforts to close Bulger as an informant. He said Fitzpatrick was motivated in part by a desire to promote sales of a book he co-authored, "Betrayal: Whitey Bulger and the FBI Agent Who Fought to Bring Him Down."

Hafer said Fitzpatrick lied when he said he recovered the gun used in the King assassination and when he testified he arrested Mafia underboss Gennaro Angiulo in 1983.

During Bulger's trial, Assistant U.S. Attorney Brian Kelly pressed Fitzpatrick about his characterization of his role in the King case.

"Isn't it true that three Memphis police officers found the rifle that was used to kill Martin Luther King, not Bob Fitzpatrick?" Kelly asked.

"I found the rifle along with them," Fitzpatrick replied. "They could have been there ... but I'm the one that took the rifle."

The prosecution and defense agreed to recommend a sentence of two years of probation. Under a binding plea agreement, Judge Dennis Saylor IV can either accept the agreement or reject it and allow Fitzpatrick to withdraw his guilty plea. Sentencing is scheduled for Aug. 5.

After the hearing, Fitzpatrick's lawyer, Robert Goldstein, said Fitzpatrick had "done many great things in his career."

"He and his family are looking forward to putting this behind him," Goldstein said.

Bulger, now 86, was convicted in 2013 of a range of gangland crimes in the 1970s and `80s, including roles in 11 murders. He's serving a life sentence.