Rosean Hargrave leaves the State Supreme Court in Brooklyn after his release. (Jesse Ward/For New York Daily News)

Rosean Hargrave entered prison as a teenager after he was found guilty of murdering an off-duty corrections officer in 1991. On Tuesday, a Brooklyn judge ruled that Hargrave’s conviction was based on flawed detective work and set him free.

Former New York Police detective Louis Scarcella was “engaged in false and misleading practices,” Brooklyn Supreme Court Justice ShawnDya L. Simpson wrote in her decision as she vacated Hargrave’s 30-year-to-life sentence.

“I have never been so happy in 23 years,” Hargrave’s mother, Shirley, said outside the Brooklyn courthouse, the New York Times reported. “I’m just so glad it’s over, and I hope it never happens to anyone else.”

Simpson wrote that the piece of evidence that served as the basis for Hargrave’s conviction was a single witness — the slain officer’s partner — who identified Hargrave in a photo array set up by Scarcella and his partner, Stephen Chmil.

Scarcella’s work from the 1980s and 1990s has come under intense scrutiny, and five of his convictions have already been vacated. Another 70 of them are under review by prosecutors. Scarcella has denied wrongdoing and claimed that he remembered little about Hargrave’s case. “I did nothing of substance,” he testified in September.

The judge wrote that “the pattern and practice of Scarcella’s conduct which manifest a disregard for rules, law and the truth undermines our judicial system and gives cause for a new review of the evidence.”

[Ohio man exonerated after spending 27 years in prison for a murder he didn’t commit]

FILE- In this March 27, 2013 file photo, now retired New York City Police Detective Louis Scarcella poses for a photo after being interviewed in New York. After some of his investigative tactics came under scrutiny, the District Attorney in the Brooklyn borough of New York ordered his Conviction Review Unit to re-examine more than 50 cases that Scarcella worked on. (AP Photo/Tom Hays, File) Retired New York City Police detective Louis Scarcella in 2013. (Tom Hays/AP)

The Times noted that Simpson’s ruling represents the first judicial review of Scarcella’s methods. “Scarcella,” Simpson wrote, “has been regarded as a legend in the N.Y.P.D. for his number of homicide arrest [sic]. There is a saying, when it is too good to be true, it usually is.”

Hargrave — who is 41, according to his attorney — was 17 when he was arrested in the murder of Rolando Neischer. 

In August 1991, Neischer and Robert Crosson, both off-duty corrections officers, were sitting in a parked car near the Crown Heights housing project where they lived. Crosson later testified that two young black men riding bikes and armed with guns approached their car and asked them to give up the vehicle. A firefight quickly broke out, and both officers were shot.

Simpson wrote that ballistics and other forensic evidence from the case have never been tested; that there was no fingerprint match from the bicycles; and that evidence that could clear the defendants had been destroyed “in bad faith.” A new trial would likely result in a different outcome, she added.

Crosson had said he knew the Hargrave family during a trial and identified Hargrave and John Bunn via a photo array and line-up arranged by Scarcella. Bunn, 14 at the time, was also convicted and sentenced to nine years to life in prison. He was released in 2006 but was sent back to prison after violating his parole.

[Alabama inmate free after three decades on death row. How the case against him unraveled.]

Bunn was released again in 2009, and although his conviction wasn’t a part of the judge’s ruling, he was in the courtroom Tuesday to support Hargrave. Bunn wept during the ruling, the Times reported.

“This is a day I always wished for,” Bunn said, according to the newspaper. “There’s no better feeling. I still can’t believe it’s real.”

Bunn’s lawyers have filed a motion asking for his conviction to be vacated, the Daily News reported.

Simpson ruled that prosecutors have 30 days to appeal her ruling.

“We’re reviewing Judge Simpson’s decision before determining what, if any, action we will take,” Mark Hale, chief of the Brooklyn district attorney’s conviction review unit, said in a statement. “Judge Simpson did not find him actually innocent in her ruling. We are reviewing the balance of her decision.”

Prosecutors would need to find new evidence within the 30-day window; otherwise a new trial would have to rely on the flawed evidence already gathered, Simpson ruled.

Two years ago, a judge overturned another Scarcella-connected conviction and freed David Ranta after he’d served 23 years in the murder of a rabbi.

Another high-profile case linked to Scarcella resulted in a $17 million wrongful conviction payout in January by the city. Alvena Jennette, Robert Hill and Darryl Austin had been convicted for murders in the 1980s and spent a combined 60 years in prison before their sentences were vacated. Austin died while in prison.

[Three half-brothers who served decades on wrongful murder convictions will receive a combined $17 million]

A woman known as a drug dealer and addict served as Scarcella’s central witness in the cases against Jennette and Austin, and she was also a witness in two different murder cases against Hill.

“The 1980s were a difficult time in our city’s history, and in a certain way, we are sort of unearthing the tangled history of that time period in our court system today,” New York City Comptroller Scott M. Stringer said when the payout was announced. “Clearly, our heart goes out to those who have been wrongfully incarcerated. We are also very concerned about the impact these cases will have on the fiscal health of the city.”

Hargrave had served time in a maximum-security facility for inmates with severe behavior problems. The Times reported that he bears a scar on his face after a fight with another inmate.“ It’s like being in a jungle with a bunch of lions,” he told the Times two years ago. “If I got a spear, I got to protect myself.”

As the judge announced her decision, Hargrave’s family burst into celebration. “Thank you, your honor!” Hargrave’s sister shouted. “Thank you, God.”