After 25 years on death row for a killing he said he didn't do — and three years after a federal judge threw out his conviction — James Dennis was brought to a Philadelphia courtroom Thursday to make a harrowing choice: plead no contest to the crime and go home, or gamble on another trial.

He didn't want to admit to the 1991 shooting of 17-year-old Chedell Williams. A federal judge had already ruled he'd been condemned "for a crime in all probability he did not commit."

But that didn't guarantee that another jury wouldn't find him guilty.

So he took the only path he knew would keep him from execution.

Related: The Wrongful Conviction of Thomas Webb III

"I need to do what I need to do for my family," Dennis told his brother, Greg, before entering the plea.

As part of his agreement with prosecutors, Dennis was able to maintain that he hadn't killed Williams.

Jimmy Dennis. Courtesy of Justice for Jimmy

"James Dennis entered a no-contest plea, not a guilty plea, because he maintains the same position that he has maintained for 25 years: that he is innocent of this crime," one of his lawyers, Karl Schwartz, told the judge. "He and his family have made this incredibly difficult decision based on his and their strong desire to have him home and free, [in] lieu of potentially years of continuing litigation."

The no-contest plea is not uncommon in claims of wrongful conviction. It allows prosecutors to keep a conviction without a new trial. The defendant, meanwhile, acknowledges there may be enough evidence for another guilty verdict but can still claim innocence.

To some, no-contest can seem like a good deal. To others, it can feel like less than justice.

Samuel Gross, a University of Michigan law professor who runs The National Registry of Exonerations, said the offer of a no-contest plea puts defendants in an agonizing bind.

Related: Inmates Hope for Last-Ditch Shot at Obama's Clemency Program

"Typically, when someone has been on death row or general prison population for most of his adult life and is now offered an opportunity to leave prison right away, their family and friends and lawyers ... urge them to take the plea and not take a chance," Gross said. "Quite a few refuse."

The results are impossible to predict.

Gross cited the case of Terry Harrington, who was convicted with a friend, Curtis McGhee, of the 1977 murder of a retired police captain in Iowa. Both were granted new trials. McGhee took a no-contest plea and was released. Harrington chose to go to trial, but prosecutors dismissed the case instead. The dismissal resulted in his release and exoneration. But only later, after a lawyer found evidence that the prosecutors had improperly handled McGhee's plea, was he exonerated as well.

Lawyers also negotiated no-contest pleas in the case of the West Memphis 3 — men who were convicted of killing three Arkansas Cub Scouts in 1993. Not all of the three men wanted to enter the plea, but they agreed because one of them, Damien Echols, was suffering severely from 18 years on death row.

Related: President Obama Commutes Another 79 Inmates' Prison Sentences

Dennis was convicted in 1992 of shooting Williams during a robbery, primarily on the testimony of three eyewitnesses. Decades of appeals followed, in which his lawyers argued that investigators and prosecutors withheld evidence that undermined his innocence. It landed before U.S. District Judge Anita Brody, who in 2013 ripped into the prosecution and ordered a new trial.

"The Commonwealth of Pennsylvania has committed a grave miscarriage of justice in convicting Dennis and sentencing him to die for this crime," Brody wrote.

A photograph of Jimmy Dennis as used by the Justice for Jimmy campaign. Courtesy of Justice for Jimmy

Philadelphia District Attorney Seth Williams, who was not in office when Dennis was convicted, challenged the ruling. An appellate court sided with her in August.

That forced Williams to decide whether to retry Dennis or drop the case. Unwilling to say Dennis was innocent, his office began negotiations with Dennis' lawyers.

One of Dennis' lawyers, Stephen Cozen, said in an interview that he considered the state's witnesses as "shaky" and Dennis' alibi — that he was a on a bus miles away when the murder took place — as strong.

Ultimately, Dennis agreed to the plea because it allowed him to continue to assert that he didn't kill Chedell Williams.

"Our main goal was to try to get Jimmy out of prison after having served 25 years," Cozen said.

Prosecutors said they remained convinced of Dennis' guilt.

"In our system of justice, the defendant is always free to state otherwise. Under the law, however, he stands convicted of this murder," Williams' office said in a statement. "We accepted this plea not because of doubts about guilt, but because of the inherent difficulties of retrying a complex case more than a quarter century after the crime."

Jimmy Dennis poses while holding a photograph of his mother. Courtesy of Justice for Jimmy

The remaining complication was an unrelated robbery conviction, according to Dennis' lawyers. Dennis didn't dispute that one. But that punishment remained on the books.

The two sides worked out a deal where prosecutors would recommend that Dennis receive parole, possibly in time to be home by Easter, Cozen said. He praised Williams' office for negotiating the deal.

Dennis' older brother, Greg, said the family is now planning a homecoming. But the reunion will be bittersweet.

He criticized Williams for not dismissing the case.

"We're happy that we'll get to spend some time with Jimmy and be with him, but we also feel very disrespected," he said.