The judge also tossed out Terrance "Terry" Williams' death sentence, granting him a new sentencing hearing. She upheld his first-degree murder conviction.
Williams has been on death row for 28 years and was set to be executed Wednesday. He would have been the first person executed in Pennsylvania in 50 years who had not given up his appeals.
Williams, now 46, could still face the death chamber if the state Supreme Court overturns Friday's ruling. Prosecutors were filing an appeal late Friday.
Common Pleas Judge M. Teresa Sarmina accused trial prosecutor Andrea Gelman Foulkes of "gamesmanship" in order to win the 1986 death-penalty case.
"She did at times play games and take unfair measures to win," Sarmina said Friday, reading her lengthy opinion aloud.
Terry Williams was not in court, but his aunt, daughter and other supporters broke into applause.
Given new evidence unearthed only this past week from police homicide files and Foulkes' own notes, Sarmina said the jury might have spared Williams if they knew more about victim Amos Norwood and his alleged penchant for teen boys.
Accomplice Marc Draper, a childhood friend, recanted his trial testimony this year as Williams' execution loomed. That led to what the judge called the "extraordinary" late-stage evidence hearing this past week, when Sarmina called Draper and Foulkes to the witness stand.
Foulkes acknowledged that she had suspected a sexual relationship between the 56-year-old Norwood and 18-year-old Williams. However, police statements from Norwood's wife and pastor about prior fondling complaints and odd interactions with teenage boys never reached the defense lawyer or jurors.
Williams now says he had been abused since he was 13 by Norwood, a chemist and deacon who often worked with disadvantaged boys through a church theater program.
Williams, a star high school quarterback from a troubled family, was secretly having sex with older men in exchange for money, clothes and gifts. He had killed 50-year-old Herb Hamilton five months earlier, when he was 17, in a gruesome, clearly sexual slaying. Foulkes herself had prosecuted Williams in that case, which raised the sex motive and resulted in a third-degree murder conviction.
Philadelphia District Attorney Seth Williams, at an afternoon news conference, defended Foulkes and said Sarmina had "unfairly victimized" her.
"How in the world could the prosecutor have 'suppressed' information that was in the defendant's own head?" the district attorney asked.
He said he supports the death penalty in only "a tiny fraction" of cases, but puts Terry Williams in that group because he had "brutally" killed two men, lied on the stand and raised sex-abuse claims only years later.
Draper had long refused to talk to Terry Williams' appellate lawyers. But angry over a cooperation deal that left him with a life sentence, he agreed to talk this year. He testified Monday that he had told Foulkes and police about Williams' sexual relationship with Norwood, but they didn't want to hear it.
Sarmina ordered prosecutors to bring the original police files to court. Interview notes made by Foulkes and by police corroborated Draper's story.
Draper said he'd been promised a chance for parole after 10 or 15 years if he left out the sex motive. Instead, he got a life sentence - which in Pennsylvania, means life without parole.
Foulkes had stated at trial that she had no side deals with Draper. Yet she later wrote a letter promising to confirm his cooperation if he was ever up for parole. Unbeknownst to Draper, that could only happen if his sentence was changed on appeal.
Foulkes' supervisors at the U.S. Attorney's Office, where she has spent the past 22 years, also came to her defense.
"Andrea Foulkes is an outstanding prosecutor with an impeccable record for integrity, professionalism, and dedication to public service," First Assistant U.S. Attorney Louis Lappen said in a statement.
Federal courts had previously found the work of Williams' now-disbarred trial lawyer "unconstitutionally deficient," although they stopped short of throwing out the death sentence.
Federal public defenders who work solely on death-penalty cases have represented Williams since 1996. They say the errors found in his case are not uncommon. Pennsylvania has about 200 people on death row.
"That we were talking about executing somebody who meets his lawyer a day before trial is an indictment of the system. The fact we're talking about this new evidence a week before execution is a bigger indictment of the system," public defender Victor Abreu said.
Williams still has a clemency petition pending with the state Board of Pardons, which reopened his case Thursday but did not rule.
"He's hanging in there. It's not an easy situation," said Shawn Nolan, another public defender.