The Pennsylvania Supreme Court overturned Bill Cosby’s 2018 sexual assault conviction on Wednesday and barred him from being retried, a decision that will pave the way for his release from prison and upend the first high-profile celebrity conviction of the #MeToo era.

The divided court ruled that the 83-year-old comedian — who has served more than two years of a three-to-10-year sentence — had been denied a fair trial, citing an agreement struck with a previous prosecutor that the justices said barred Cosby from ever being charged with the 2004 assault of Temple University employee Andrea Constand.

Justice David N. Wecht, writing for the majority, said Montgomery County District Attorney Kevin R. Steele was legally bound by that decade-old promise and therefore should not have brought charges when new evidence surfaced in 2015.

Vacating Cosby’s conviction, Wecht said, “is the only remedy that comports with society’s reasonable expectations of its elected prosecutors and our criminal justice system.”

The decision could result in Cosby’s release from the state prison in Montgomery County as early as Wednesday afternoon.

“Work is underway to complete the necessary paperwork,” said Maria Bivens, a spokesperson for the Pennsylvania Department of Corrections. “Mr. Cosby will be released as soon as practical.”

Spokespersons for Cosby, Constand and the Montgomery County District Attorney’s Office did not immediately respond to requests for comment.

The case had a complicated history that began in 2005 when Constand first reported the alleged assault to the office of then-Montgomery County District Attorney Bruce L. Castor Jr., who ultimately declined to file charges in this case.

At the time, Castor said he was not confident her allegations would hold up to scrutiny in a criminal court. But he maintained he struck the non-prosecution deal with Cosby to compel him to testify in a civil suit that Constand had separately filed against him, hoping that at least she could find justice in civil court.

No evidence has been presented that this agreement was ever memorialized in writing. But Castor has previously cited a news release he issued on the decision in 2005 as binding on all prosecutors that succeeded him.

Castor’s successors reopened the case and charged Cosby in 2015, just days before the 12-year statute of limitations expired and amid a barrage of new accusations from women across the country.

Excerpts from Cosby’s deposition in the Constand’s civil suit were ultimately used against Cosby at trial in what the high court justices described Wednesday as a violation of his constitutional rights to due process.

“”When a prosecutor makes an unconditional promise of non-prosecution, and when the defendant relies upon that guarantee to the detriment of his constitutional right not to testify … our criminal justice system demands that the promise be enforced,” Wecht wrote.

Staff writer Anna Orso contributed to this report.

The Pennsylvania Supreme Court has overturned Bill Cosby’s 2019 sexual assault conviction. Here, you can read the opinions of the justices in full.

j-100-2020mo-104821740139246918