The Pennsylvania Supreme Court overturned Bill Cosby’s 2018 sexual assault conviction on Wednesday and ordered him freed from prison, a dramatic development that upended the first high-profile celebrity conviction of the #MeToo era.

The divided court made no findings on the sufficiency of the evidence against the 83-year-old comedian.

Instead, it based its decision on a question that had bedeviled the case from the start: whether a prior prosecutor’s decade-old promise that Cosby would never be charged with drugging and assaulting accuser Andrea Constand prohibited the Montgomery County District Attorney’s Office from lodging the case that ultimately led to his conviction.

» READ MORE: What’s next for Cosby? A reunion with family, lawsuits from accusers, a return to the stage, and ‘extra crunchy’ pizza

Justice David N. Wecht, writing for the majority, found that it did, citing Cosby’s reliance on that vow when he agreed to give incriminating testimony in a civil case Constand had filed against him — testimony that the justices said was improperly used years later against Cosby at his criminal trial.

“This was … an unconstitutional coercive bait-and-switch,” Wecht wrote, noting that such a “vast” due-process violation required an equally drastic remedy.

Ultimately, the court barred prosecutors from ever retrying Cosby on the Constand charges again — a decision that drew dissents from three members of the court.

» READ MORE: Read the Pa. Supreme Court’s opinion in the Bill Cosby trial

Still, within hours, Cosby walked out of the state prison near Collegeville where he had already served more than two years of his three-to-10-year sentence. And a case that spanned 16 years and had been hailed as a landmark achievement in holding celebrities accountable for past sexual misconduct had crumbled to dust.

Returning to his Elkins Park estate, Cosby eventually emerged to greet supporters gathered outside the gates. Leaning on one of his lawyers for support, and dressed in a Central High T-shirt and velvet shoes with dogs embroidered on them, he flashed a V-for-victory sign but declined to address the crowd.

When a reporter asked Cosby how he was feeling, his lawyer Jennifer Bonjean interjected: “He says his heart is just beating really fast.”

He tweeted later thanking his fans, the court, and those who stood by him.

“I have never changed my stance nor my story,” he said. “I have always maintained my innocence.”

District Attorney Kevin R. Steele, who won his post in 2015 in part by vowing to put Cosby on trial and later led the prosecution team, was quick to point out that the high court had not overturned Cosby’s conviction based on innocence but rather what he described as “a procedural issue irrelevant to the facts of the crime.”

In a statement, Steele commended Constand and the dozens of other women who have since come forward to accuse Cosby of similar assaults for “remaining steadfast throughout this long ordeal.” His office did not say whether it intended to petition the court for a rehearing on the decision.

For her part, Constand, in a joint statement with her lawyers, described the court’s ruling as a disappointment.

“It may discourage those who seek justice for sexual assault in the criminal justice system from reporting or participating in the prosecution of the assailant or may force a victim to choose between filing either a criminal or civil action,” it said.

» READ MORE: ‘It’s a dark day’: Reaction as Bill Cosby released from prison after conviction overturned

The issue that brought down the case Wednesday had been present from the start of its tortured history — one that began with Constand’s first report to police in 2005, the year after the alleged assault, and included years of costly litigation, contentious pretrial battles, a first trial in Norristown that ended with a hung jury after days of toiling deliberations and a retrial where a second jury ultimately convicted him.

When Constand, then a Temple University sports administrator, first reported her alleged assault, the district attorney at the time — Bruce L. Castor Jr. — said he doubted her allegations would stand up in court, given her delay in reporting them, and declined to press charges.

In doing so, Castor would say years later, he struck a deal with Cosby that he thought could help Constand find justice in civil court instead. As Castor described it, he promised Cosby would never be prosecuted because the comedian agreed to sit for a deposition in Constand’s civil case without exercising his Fifth Amendment rights against self-incrimination. That case ended with a $3.4 million settlement.

Though no evidence was presented that the agreement was ever formalized, Cosby’s lawyers immediately objected when Castor’s successor, former District Attorney Risa Vetri Ferman, charged Cosby 10 years later, just days before the 12-year statute of limitations on the crime expired.

Testifying for Cosby’s defense in a 2016 pretrial hearing seeking the case’s dismissal, Castor asserted that a vaguely worded news release he issued at the time of his decision not to charge Cosby was legally binding on all prosecutors who succeeded him in office. A Montgomery County judge determined that Castor was not a credible witness and that there was no evidence beyond his word to support that the deal had ever existed.

In the Supreme Court decision Wednesday, most of the justices agreed that Castor’s legal reasoning was dubious but ruled that what mattered was what Cosby and his lawyers in 2005 reasonably believed to be true at the time.

“When a prosecutor makes an unconditional promise of non-prosecution, and when the defendant relies upon that guarantee to the detriment of his constitutional right not to testify … our criminal justice system demands that the promise be enforced,” Wecht wrote in the opinion joined by five of his colleagues.

Excerpts from Cosby’s deposition in Constand’s civil case— in which he discussed using quaaludes in sexual liaisons with other women — were ultimately used against Cosby at trial. But the damage went far beyond that, Wecht wrote, prompting the majority’s decision to bar a retrial.

Justice Kevin R. Dougherty and Chief Justice Max Baer, while agreeing to overturn the conviction, dissented from that drastic remedy, saying they would have authorized a new trial without the incriminating deposition testimony and that Castor’s alleged deal shouldn’t spare Cosby from prosecution forever.

“If district attorneys had the power to dole out irrevocable get-out-of-jail free cards at will and without judicial oversight, it would invite a host of abuses,” Dougherty wrote, adding in a footnote that “one might reasonably wonder if such abuses were at work in this case, particularly given Castor’s odd and ever-shifting explanations for his actions.”

Castor, in an interview Wednesday, said he felt vindicated by the court’s decision but remained indifferent to Cosby’s release.

» READ MORE: Bill Cosby’s release from prison again shines a light on Bruce Castor. And Castor feels ‘vindicated.’

“I don’t feel any regret that he got out,” he said. “And I don’t feel any satisfaction that he got out.”

The court’s majority did not engage with the other central question at the heart of Cosby’s appeal: whether testimony from five other Cosby accusers prosecutors called as witnesses to bolster Constand’s story — and to show his alleged assault against her fit a pattern of predatory behavior — had unduly tainted the jury against him.

In his dissent, Justice Thomas G. Saylor said he would have overturned the case on those grounds.

One of those trial witnesses, Janice Baker-Kinney — who has alleged Cosby assaulted her in Reno, Nev., in the 1980s — said Wednesday that while stunned by the decision, she and Cosby’s other accusers remain proud of the role they played in the case.

“We still have a great support system,” she said. “And we’ll get through this the same way we did, when we first came out with our truths.”

» READ MORE: Bill Cosby’s release leaves accusers dismayed, but women’s advocates say no court can erase their ‘courage and resolve’

Cosby, meanwhile, was continuing his victory lap. As dusk fell, he phoned in to Philadelphia R&B radio station WDAS.

“This is for all the people who have been imprisoned wrongfully regardless of race, color, or creed, because I met them in there,” he said, before abruptly signing off, adding: “My wife is waiting for me.”

Staff writers Anna Orso and Jeff Gammage contributed to this article.

Read the majority opinion: