Bill Cosby’s sexual assault conviction was overturned by the Pennsylvania State Supreme Court on Wednesday (June 30) after the court found that an agreement with a previous prosecutor prevented him from being charged in the case. The 83-year-old actor and comedian is now set to be released from a state prison near Philadelphia, where he has served two of his three-to-10-year sentence.

Cosby was accused of drugging and molesting a woman, Andrea Constand, at his home in 2004. He was charged for the incident in 2015 and arrested just days before the 12-year statute of limitations would have expired. He was convicted of three counts of aggravated indecent assault in 2018 at his second trial after a first trial resulted in a hung jury.

On Wednesday, the Pennsylvania high court said District Attorney Kevin Steele broke his predecessor’s promise to not criminally charge Cosby when he gave incriminating testimony during Constand’s civil suit.

Former District Attorney Bruce Castor reportedly told Cosby he would not be tried criminally if he testified during Constand’s civil suit. During that deposition, Cosby gave incriminating statements about drugging women, which Steele later presented at trial. The Pennsylvania high court said Steele broke Castor’s agreement with Cosby and therefore overturning his conviction “is the only remedy that comports with society’s reasonable expectations of its elected prosecutors and our criminal justice system.”

The court also referenced the number of accusers who were allowed to testify in Cosby’s retrial. For his first trial, the judge allowed just one other person to testify against him. However, five more accusers were allowed to testify at the retrial. The Pennsylvania high court said this tainted the trial, although a lower appeals court previously said it was appropriate to show the pattern of allegations against Cosby.

In overturning his conviction, the court also barred any retrial or further prosecution against Cosby in the case.