For more than 20 years, Michael Vecchione served as one of Brooklyn District Attorney Charles “Joe” Hynes’ top lieutenants, taking on some of the office’s most controversial cases. Earlier this week, he filed his retirement papers, bringing his career as a prosecutor to a close.

His departure comes on the heels of two resounding electoral defeats for Hynes, both by former federal prosecutor Kenneth Thompson. Hynes lost in the Democratic primary in September and again in the general election earlier this month, when he ran as a Republican. Hynes is scheduled to cede the office to Thompson on December 31.

For much of Hynes’ tenure, Vecchione was by his side, running the most powerful divisions of the office, first as chief of homicide in 1992 and later taking over the rackets division in 2001.

Vecchione often prosecuted the office’s most high-profile cases. He earned a reputation as an effective trial attorney, but was sometimes criticized by judges, defense lawyers and former colleagues as being willing to bend ethics rules to win convictions. He’s leaving the office before Thompson can follow through on a pledge to fire him come January.

Earlier this year, ProPublica chronicled Vecchione’s career, finding that he was at the center of some of the office’s most embarrassing scandals. In 2007, Vecchione tried to bring a murder conspiracy case against a former FBI agent, but it imploded when the court learned that a star witness had given inconsistent accounts of the murder accusations. In 2003, the Brooklyn District Attorney’s office agreed to release a man it believed responsible for multiple murders after it came to light that Vecchione withheld evidence in the man’s original trial. Last year, a member of Vecchione’s sex trafficking unit resigned following accusations that she withheld a victim’s recantation in a rape case.

But he’s perhaps best-known for his involvement in the wrongful conviction of Jabbar Collins, a Brooklyn man who served 16 years in prison for a murder he didn’t commit. Collins is now suing the city for $150 million, accusing Vecchione of coercing witnesses, withholding evidence and suborning perjury at his trial in 1995.

In 2010, Federal Judge Dora Irizarry issued a withering rebuke of Vecchione’s conduct in the case, saying it was “beyond disappointing” in a decision to toss Collins’ conviction.

“It is really sad that the D.A.’s office persists in standing firm and saying they did nothing wrong here,” Irizarry said.

In June, Vecchione was forced to give sworn testimony about his conduct in the case. He offered little in the way of explanation; instead, he answered questions with some version of “I don’t recall” 324 times. The second part of his deposition is tentatively scheduled for January.

In the face of all this criticism, Hynes has consistently defended Vecchione, calling him a “very principled” lawyer at a press conference following Irizarry’s opinion.

Hynes also allowed Vecchione to represent the office as a key character in the CBS reality show “Brooklyn DA,” which aired earlier this year.

Neither Vecchione nor the Brooklyn DA’s office immediately responded to calls for comment. If they do, we’ll update this story.