Scandal-scarred NYPD Det. Louis Scarcella blamed his tarnished legacy on former Brooklyn District Attorney Charles Hynes Monday as the embattled retired cop was grilled for his role in putting a Brooklyn man behind bars for 18 years.

“Mr. Hynes was completely wrong,” Scarcella whined under questioning by defense attorney Ron Kuby during a hearing in the wrongful conviction case of Sundhe Moses.

Kuby had been grilling Scarcella over public allegations Hynes and others had made stating Scarcella was responsible for witness tampering and mishandling of evidence in another wrongful conviction case.

“[Hynes] was throwing me under the bus, he lied,” the fallen ex-cop said, responding to questions about his role in the conviction of David Ranta — who spent 23 years behind bars in the killing a rabbi before his conviction was tossed in 2013.

“There was no wrongdoing on my part in any of the cases,” the former detective asserted.

Moses, who was paroled in 2013, claims Scarcella choked him, blew cigar smoke in his face, forced him to strip naked and threw a chair at him to elicit his confession in the 1995 murder of a 4-year-old Brooklyn girl.

Hynes publicly blasted Scarcella in a 2013 in a 2013 note he wrote to the New York Times, pleading for their endorsement as he was seeking reelection.

“During the course of the [David] Ranta investigation, [we] uncovered some questionable conduct by former NYPD Detective Scarcella,” Hynes wrote in an unsuccessful attempt to win their endorsement.

“In announcing our decision to release Mr. Ranta, we made it clear that the decision was made in part because of the conduct of Det. Scarcella,” Hynes wrote in an email, released by the city Department of Investigation in 2014.

Hynes later opened investigations into all of the detective’s homicide cases.

Roughly 70 of Scarcella’s homicide cases are under investigation by the DA’s conviction-review unit. He continues to defend his work.

Scarcella spent most of Monday morning hemming and hawing on the stand, answering many of Kuby’s questions with: “I have no memory of that whatsoever.”

“I did not fabricate anything,” an increasingly agitated Scarcella said at one point as Kuby continued to drill him, looking for inconsistencies.

“You know me, we go so far back that you were the hero and I was the villian,” Kuby quipped at one point.

Scarcella also denied he had worked in any capacity on the case of Rosean Hargrave, who spent 23 years behind bars after he was found guilty of killing a correction officer in a botched carjacking. His conviction was tossed in 2015, with the judge citing “Scarcella’s malfeasance.”

“I did no detective work whatsoever” in the Hargrave case, the ex-detective insisted. “My name was on the folder as case detective, but I maintain to this day I did very little in this case.”

A disgruntled-looking Scarcella declined comment as he left court.

Moses, who was released on parole in 2013, and Kuby are slotted to return for more hearings May 26.

“This is not a tale of one bad detective,” Kuby said after the hearing. “This is a tale of an exceptional detective who was able to thrive in an utterly corrupt system of justice. And he seems a little angry that he is the only one being held to account for it.”

“I agree with Mr. Kuby that Lou was an exceptional detective, and he is angry at being portrayed as a corrupt and evil man,” Scarcella’s attorney, Joel Cohen, later said in a statement.

“Ken Thompson, the late Brooklyn district attorney, said that no misconduct by Scarcella played a part in any decision his office made to vacate a murder conviction,” Cohen added. “Yet Lou is still portrayed in the media the poster child for wrongful convictions.”