A man who was put away for 24 years by shady ex-NYPD Detective Louis Scarcella stepped out of a courtroom Monday a free man – after the Brooklyn DA’s Office announced it wouldn’t retry him for the decades-old murder.

Rosean Hargrave, 44, heaved with emotion and burst into sobs in Brooklyn Supreme Court, where he learned he was at long last cleared of murdering off-duty corrections officer Rolando Neischer in 1991.

“It’s been 27 years,” Hargrave said outside the courtroom. “There were times I saw death — that is how badly corrections officers beat me for a crime I did not commit.”

Hargrave was just 17 years old when he and co-defendant John Bunn, who was 14, were found guilty of Neischer’s death.

Fingerprints found at the scene didn’t match either teen — and the lone witness gave conflicting descriptions of the suspects, saying they were light-skinned and in their 20s.

Both Hargrave and Bunn are dark-skinned.

In 2015, Brooklyn Supreme Court Justice ShawnDya Simpson vacated Hargrave’s conviction and granted him a new trial – saying he was convicted “based solely on identification of evidence” brought by Scarcella, then a star detective, and his partner.

He was released from prison after serving more than two decades behind bars.

“The revelation of Detective Scarcella’s malfeasance in fabricating false-identification evidence gravely undermines the evidence that convicted the defendant in this case,” Simpson wrote in her decision.

The DA’s office appealed – and a dark cloud hung over Hargrave for the next two and a half years as prosecutors challenged Simpson’s ruling.

But last month, a panel of appellate judges unanimously affirmed Simpson’s decision.

The DA’s office decided not to retry him.

“It’s been a long time coming,” Simpson told Hargrave Monday, as his girlfriend and cousin sat in the courtroom.

Asked what he’ll do now that he’s been cleared, Hargrave simply said, “I will breathe.”

He hugged his attorney Pierre Sussman – who joined him afterward for a celebratory catfish meal at Junior’s.

“He is the only one who truly believed in my innocence, apart from my family. He came out of nowhere to help me,” Hargrave said. “I was framed for murder.”

Sussman added, “Now he’s completely cleared. He’s a normal citizen. He’s not a defendant anymore. He has no criminal case, he has no felony record.

“The last three years being on the outside was torture because he was waiting to clear his name. And that’s just psychologically very tough to handle for anyone.”

Simpson also granted Bunn – who was paroled in 2009 — a new trial, which is pending an appeal by prosecutors.

“Given the totality of circumstances, including the fact that the homicide was committed nearly 27 years ago, we are unable to retry this case and therefore agreed to dismiss the indictment in the interest of justice,” a DA spokesman said.

Other convictions tied to Scarcella’s work have also been tossed.