THE U.S. Supreme Court ruled Thursday that former Pennsylvania Chief Justice Ronald Castille was wrong to participate in an appeal from a death-row inmate whose prosecution he oversaw nearly three decades before.

In a 5-3 split, the justices ordered a new hearing for Terrance Williams, finding that Castille's involvement in hearing the case when it came before the Pennsylvania Supreme Court in 2014 violated Williams' constitutional rights.

The decision served as a sharp rebuke to Castille, one of the Pennsylvania legal system's most towering figures in recent years. It also delivered a potential lifesaver to Williams, whose case has become a rallying point for death-penalty critics since Gov. Wolf cited it in declaring a moratorium on capital punishment two years ago.

"Bias is easy to attribute to others and difficult to discern in oneself," U.S. Supreme Court Justice Anthony M. Kennedy wrote Thursday for the majority, joined by Justices Ruth Bader Ginsburg, Stephen G. Breyer, Elena Kagan, and Sonia Sotomayor.

He added: "When a judge has served as an advocate for the state in the very case the court is now asked to adjudicate, a serious question arises as to whether the judge, even with the most diligent effort, could set aside any personal interest in the outcome."

Williams' appellate lawyer Shawn Nolan hailed the ruling as a victory.

"Today, Terry Williams comes one step closer to the new, fair sentencing hearing he deserves," said Nolan, chief of the capital habeas unit of the Federal Community Defender Office. "We're optimistic that the Pennsylvania Supreme Court will give this case careful consideration and recognize the injustice of Terry's death sentence."

Castille, a Republican who retired from the court in 2014, responded swiftly, saying his role as a prosecutor in Williams' case had been "merely procedural."

As Philadelphia district attorney in 1986, he had signed off on the decision to pursue the death penalty for Williams, who was convicted in the beating death of a Germantown church deacon.

He was also one of six state Supreme Court justices who unanimously voted to reinstate Williams' death sentence in 2014 after a Common Pleas Court judge had overturned it.

He called the court's decision Thursday "ill thought-out."

"It's the liberal wing of the court, changing the law [on when a judge should recuse] that was pretty clear before," Castille said. "It will have far-reaching consequences for anyone who is a former prosecutor."

The U.S. Supreme Court's dissenting members - Chief Justice John G. Roberts Jr., and Justices Samuel A. Alito Jr. and Clarence Thomas - agreed, arguing that it should be left up to states and local judicial ethics boards to draw the lines on when judges should step aside. Yet even they described Castille's decision to hear Williams' appeal as "unwise."

Williams, now 49, was an 18-year-old Cheyney University football standout when he was arrested in 1984 and charged with murdering Amos Norwood. At the time, city prosecutors alleged that he bludgeoned Norwood to death in a West Oak Lane cemetery, then set his corpse on fire during a robbery.

Though Williams testified at his trial that he was innocent and had never met Norwood, he has since contended through his lawyers that the killing was motivated by five years of sexual abuse he suffered at Norwood's hands as a teenager.

The U.S. Supreme Court's decision Thursday centered on a 2014 hearing in which the Pennsylvania Supreme Court affirmed Williams' death sentence, despite a finding from a lower court that prosecutors had withheld evidence that might have aided in his defense.

Cameron Kline, a spokesman for the office, said Thursday that its appellate division would persist in its efforts to keep Williams on death row.

"We are confident that the Pennsylvania Supreme Court, without Justice Castille, will rule the same way," he said.