A court has overturned Bill Cosby’s sex assault conviction after finding an agreement with a previous prosecutor prevented him from being charged in the case.

The 83-year-old former stand-up comedian and actor has already served more than two years of a three-to-10-year prison sentence in Philadelphia, Pennsylvania.

He had vowed to serve all 10 years rather than acknowledge any remorse over the 2004 encounter with accuser Andrea Constand.

Cosby, who was once beloved as “America’s Dad,” was charged in 2015 when a prosecutor armed with new evidence arrested him days before the 12-year statute of limitations expired.

But Pennsylvania’s highest court said that District Attorney Kevin Steele, who made the decision to arrest Cosby, was obligated to stand by his predecessor’s promise not to charge the actor after he gave potentially incriminating testimony in a civil suit brought by Ms Constand.

Justice David Wecht, writing for a split court, said Cosby had relied on the former prosecutor’s promise and that overturning the conviction, and barring any further prosecution: “is the only remedy that comports with society’s reasonable expectations of its elected prosecutors and our criminal justice system”.