The Pennsylvania Supreme Court freed the actor Bill Cosby from prison based largely on a past agreement with a former Pennsylvania prosecutor best known for defending President Donald J. Trump during his February impeachment trial.
In a 79-page opinion, the Pennsylvania Supreme Court wrote that a “non-prosecution agreement” that had been struck with Bruce L. Castor Jr. meant that Bill Cosby should not have been charged in the case for which he was convicted and sentenced in 2018. The court also barred a retrial.
The agreement came about when, in 2005, Mr. Cosby was investigated in the case of Andrea Constand, and Mr. Castor, a former district attorney of Montgomery County, gave Mr. Cosby his assurance that he would not be charged in the case.
Mr. Castor testified that while there was insufficient evidence to bring a criminal prosecution, he had given Mr. Cosby the assurance to encourage him to testify in a subsequent civil case brought by Ms. Constand.
In that testimony, Mr. Cosby acknowledged giving quaaludes to women he was pursuing for sex — evidence that played a key part in his trial after Mr. Castor’s successors reopened the case and charged Mr. Cosby in December 2015.
“In light of these circumstances, the subsequent decision by successor D. A.s to prosecute Cosby violated Cosby’s due process rights,” the appeals ruling said.