Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

For nine years, Davontae Sanford has been incarcerated for the murder of four people at a Detroit drug house. He was just 14 in September 2007 when police found him in his pajamas near the crime scene, and after two days of interrogations, announced that he had confessed.

But on Wednesday, Sanford is expected to walk out of prison a free man. Prosecutors acknowledge the now-23-year-old had known the truth all along: He didn't do it.

Related: ACLU Fights For Juveniles Facing Life Without Parole

"Justice was not done (initially), but justice was done today," state assistant public defender Valerie Newman told NBC affiliate WDIV on Tuesday, when a Wayne County judge ordered Sanford's release.

His family "of course are thrilled," Newman added. "His mom was screaming and crying and every emotion you can imagine pouring out of her."

A judge on June 7, 2016, ordered the release of Davontae Sanford, who is in prison after pleading guilty to killing four people at age 14, a crime for which a professional hit man later took responsibility. AP

The road from convicted killer to wrongly accused in the eyes of the justice system took years — and a seemingly endless and winding appeals process.

A hit man, already imprisoned for other murders, had given police a detailed affidavit in March 2015 saying that he was responsible for the homicides and that Sanford — who was sentenced to 37 to 90 years in prison — took no part in it.

Pro bono attorneys with Northwestern’s Center on Wrongful Convictions of Youth and the Michigan Innocence Clinic at the University of Michigan Law helped Sanford's legal battle.

The Morning Rundown Get a head start on the morning's top stories. This site is protected by recaptcha

Related: Dateline Digital Series: Conviction

"The justice system took many years to acknowledge the complete breakdown that allowed for Davontae to sit in prison for nine years," David Moran, director of the Michigan Innocence Clinic, said in a statement. "Davontae can now return to his family and, for the first time in his adult life, live as a free man."

Moran said the case puts a spotlight on the unreliability of confessions — particularly by children — and the need for them to have counsel present when they are interrogated.

"Here, a 14-year-old kid confessed to a crime he did not commit only after he had been interrogated repeatedly over the course of two days without an attorney, or even a parent, present," Moran added. "His confession made little sense and got more wrong than right."

How could Sanford have been "unjustly railroaded," critics asked?

"His confession made little sense and got more wrong than right."

Sanford lived near the scene of the murders in Detroit's northeast side, and had been standing outside when police were looking for witnesses. They took him in, and believed he had key information.

But his defenders noted that Sanford, who was developmentally impaired and blind in one eye, was known for telling elaborate tales that weren't true. Police, however, ran with his confessions.

At his 2008 trial, with what critics called shoddy legal representation, Sanford pleaded guilty to second-degree murder in order to get a plea deal. His attorney at the time didn't try to suppress the confession.

But after the trial finished, someone else came forward to claim responsibility. Vincent Smothers — who was in prison for eight other murders — said he was hired to kill the people at the house.

Despite the twist in the case, a judge in 2012 denied a motion for Sanford to repeal his plea, instead finding what he told police was still valid.

Davontae Sanford's family says they're grateful the Michigan Innocence Clinic is fighting for a new trial pic.twitter.com/8wY6EU2J8M — Kate Wells (@KateLouiseWells) April 15, 2015

In 2014, pro bono attorneys took on the case. The following year, Smothers came forward again, this time in a 26-page confession to deny Sanford's involvement.

"I had never met, spoken with, or even heard of Davontae Sanford or anyone connected to him," Smothers said. "Davontae Sanford is being wrongly incarcerated for a crime that I know he did not commit."

Based on the affidavit, a motion was filed by Sanford's attorneys, and Wayne County Prosecutor Kym Worthy called for an investigation to re-examine the case.

The report of the investigation in May found that a former deputy chief had also contradicted sworn testimony claiming Sanford had drawn the entire diagram of the crime scene, including the location of the victims' bodies, according to the Wayne County Prosecutor's Office.

"Recognizing the importance of that testimony, attorneys from the Prosecutor’s Office worked with Sanford's attorneys ... to move to dismiss his case," prosecutors said.

Sanford's impending release would add him to a growing list of convicted Americans later found to have been wrongly imprisoned. Last year, 149 people were exonerated or had their convictions overturned, according to the University of Michigan Law School's National Registry of Exonerations.

Sanford's attorneys are hopeful he can readjust to life outside of prison — but it won't be easy.

"I think he's going to have a long road, but he's gotten a lot of support while he's been incarcerated," Newman told WDIV. "He has a very, very strong foundation, and a very, very strong family support that he has the tools to be successful."