Bill Cosby’s sex assault conviction was overturned by Pennsylvania Supreme Court on Wednesday. 

The actor, 83, was released from prison after the court ruled that the prosecutor who brought the case was bound by his predecessor's agreement not to charge Cosby.

Philip Dube, a Los Angeles County deputy public defender who was not involved in the case, told Fox News that the comedian – once dubbed "America's Dad" – was released because he was "denied due process and the benefit of an immunity agreement reached between him and prosecutors during civil litigation brought by his victims."

"In exchange for testifying at civil depositions, the elected DA in office at the time granted Cosby immunity from prosecution. That agreement lives beyond the term in office of the elected DA at the time," he explained.

BILL COSBY’S SEX ASSAULT CONVICTION OVERTURNED BY PENNSYLVANIA COURT

In 2018, Cosby was convicted of drugging and sexually assaulting Andrea Constand, a Temple University employee, at his suburban Penn., estate back in 2004.

The disgraced "Cosby Show" star has served more than two years of a three to 10-year sentence at a state prison near Philadelphia.

Bill Cosby was released from prison after serving two years of his three- to 10-year sentence after his sexual assault conviction was overturned by Pennsylvania’s highest court.

Bill Cosby was released from prison after serving two years of his three- to 10-year sentence after his sexual assault conviction was overturned by Pennsylvania’s highest court. (Jeff Golden/WireImage/Getty Images)

Neama Rahmani, president of West Coast Trial Lawyers, who is also not involved in Cosby's case, told Fox News this overturn is "unprecedented."

"There was a district attorney in Pennsylvania who declined to prosecute Cosby," he said referencing Bruce Castor, who was the Montgomery district attorney at the time. "Castor made a very public statement saying that we're not going to prosecute Bill Cosby because of insufficient evidence. Relying on that statement, Cosby and in a subsequent civil case, not a criminal case, was unable to invoke his Fifth Amendment privilege against self-incrimination."

BILL COSBY’S TV WIFE PHYLICIA RASHAD CELEBRATES HIS RELEASE FROM PRISON

"During the depositions, Cosby gives very incriminating and damaging statements. Then, there's a new DA and that person decides to prosecute the case," Rahmani said in reference.

"After the new DA takes over and during the prosecution, the DA uses those very damaging statements that Cosby made during his civil deposition… so what the Pennsylvania Supreme Court essentially said was, 'Look, you can't do this.' Even though there was no formal immunity, Cosby reasonably relied on that statement declining prosecution when he gave his deposition in the civil case, which is why he was so open."

The Pennsylvania Supreme 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 Cosby.

"Cosby was convicted in 2018 based on evidence that is inadmissible," Rahmani said. "He testified truthfully but he did so under the assumption that there would be no prosecution."

CLICK HERE TO GET THE FOX NEWS APP

The court called Cosby's arrest "an affront to fundamental fairness, particularly when it results in a criminal prosecution that was forgone for more than a decade."

The justices said 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."

Fox News' Sasha Savitsky and The Associated Press contributed to this report.