The NYPD detective whose corner-cutting investigative work, combined with a community’s blood lust for quick justice, put an apparently innocent man in prison for 23 years insists he’s being scapegoated by the very district attorney who pushed for the conviction.

“They threw me under the bus,” Louis Scarcella told The Post yesterday after DA Charles Hynes indicated he’d asked a judge to vacate David Ranta’s conviction, more than two decades after Ranta was found guilty of murdering a prominent rabbi in Williamsburg.

“I was appalled when I got the news,” the retired cop said outside his Staten Island home. “I stand by the confession 100 percent. I never framed anyone in my life. You have to be a low devil to frame someone. I sleep well at night.”

While Scarcella was sleeping, Ranta, 58, was languishing in a Buffalo prison, convicted of the February 1990 murder of Rabbi Chaskel Werzberger after a botched jewelry heist in the Orthodox Jewish community.

Today, Hynes, who was a new DA when his office prosecuted Ranta amid a public outcry for justice, will ask a judge to toss Ranta’s sentence after a review of the case by his office revealed a shoddy investigation, unreliable witnesses, and a tragic rush to judgment.

Detectives in Brooklyn at the time said there was enormous pressure to close the case.

Within hours of Werzberger’s death, then-Mayor David Dinkins sent a personal representative to the crime scene, and Hynes made a visit to the 90th Precinct, sources said.

“I still had my coat on, and in walked Hynes,” a retired detective recalled. “The DA never came out on a case. The pressure didn’t let up until we made an arrest.”

Six months passed before Ranta was arrested.

Despite a lack of physical evidence and a witness who insisted Ranta wasn’t the killer, he was convicted and sentenced to 37 years in prison.

“It’ll be good to see him on this side of the bars,” said Michael Baum, who was Ranta’s defense attorney at the time of the conviction. “There was never a doubt in my mind this guy was innocent. I made a promise that I would never forget. I have slept with this case every night for 23 years.”

Several years after the trial, a woman named Theresa Astin gave sworn statements that her husband, Joseph, had killed the rabbi before Joseph died months later in a car accident while fleeing cops. Her testimony fell on deaf ears.

Although Ranta, a petty criminal and house painter, had professed his innocence for years, his fight didn’t pick up steam until, at Baum’s urging, Hynes’ conviction-integrity unit went back over the case.

The review found Scarcella had coached a witness, and didn’t take notes after questioning Ranta, according to court papers.

Scarcella also investigated Joseph Astin after he died, but again failed to record most of those steps, according to the court papers filed by the conviction-integrity unit.

“He testified that although he had visited Theresa Astin’s home and left a card, he had never spoken to her,” according to the court papers.

“This directly contradicted Theresa Astin’s hearing testimony that Detectives Scarcella and [Stephen] Chmil had visited her the morning after her husband’s death, interviewed her, and intimated that she could collect a $20,000 reward if she provided evidence that her husband had murdered the rabbi.”

It wasn’t the first time Scarcella’s evidence came under review. Nearly two years ago, another man convicted of murder was released on parole after 20 years amid strong doubts about his guilt — and Scarcella’s evidence.

Derrick Hamilton was convicted of killing Nathaniel Cash in Bed-Stuy in 1991. That case came under scrutiny in 2011 after the sole witness against him recanted her testimony and nearly a dozen people came forward to stand up his alibi. Scarcella allegedly coerced a witness, according to a court affidavit.

“It’s a shame that somebody like him could have that much power,” said Hamilton, who filed a lawsuit against Scarcella and the city, which was dismissed. “I’m very happy for Ranta, but I’m sad I’m still fighting my conviction in court.”

Additional reporting by Reuven Fenton and Larry Celona