A Pennsylvania appeals court on Wednesday overturned the sexual assault conviction of Bill Cosby in a ruling that will set free the 83-year-old comedian.

Cosby, who was arrested in 2015 on charges of drugging and sexually assaulting a woman in 2004, had served more than two years of an up to 10-year prison sentence at a state prison near Philadelphia.

The Pennsylvania Supreme Court ruled Cosby had been denied a fair trial in 2018.

"When an unconditional charging decision is made publicly and with the intent to induce action and reliance by the defendant, and when the defendant does so to his detriment (and in some instances upon the advice of counsel), denying the defendant the benefit of that decision is an affront to fundamental fairness, particularly when it results in a criminal prosecution that was foregone for more than a decade," the court ruled.

"For these reasons, Cosby’s convictions and judgment of sentence are vacated, and he is discharged."

Cosby was convicted in April of 2018 on three counts of aggravated indecent assault. About 60 women had accused him of sexual abuse and drug assaults.

Cosby was the first celebrity tried and convicted in what became known as the #MeToo movement. The accusations were a fall from grace for Cosby, who was known as "America's Dad" for his sitcom "The Cosby Show."