Although Justin Wolfe filed a four-page handwritten confession in 2016 and pleaded guilty to ordering the murder of a fellow marijuana dealer, the U.S. Supreme Court on Monday ordered that Virginia give Wolfe a new hearing on his claim that he was coerced into the plea by vindictive prosecutors in Fairfax and Prince William counties.

The high court reaffirmed its holding issued last year, and in rulings before that, that defendants who plead guilty may still file appeals if the conviction violates the Constitution. In Wolfe’s case, after his first conviction for capital murder was overturned, prosecutors added more charges against him. He pleaded guilty to murder but claimed that the additional charges amounted to unconstitutional vindictiveness by the prosecutors. Virginia’s appeals courts declined to address the merits of Wolfe’s claim; the Supreme Court ruled they must.

The high court’s ruling is the latest twist in a nearly 18-year-old case that began with the slaying of 21-year-old Daniel Petrole Jr. in Bristow, Va., in March 2001. Petrole was a supplier of marijuana to Wolfe, then 19, and Petrole’s death uncovered a vast drug network distributing marijuana and ecstasy to high-schoolers throughout Northern Virginia. Prince William prosecutors alleged that Wolfe asked his friend Owen Barber to rob and kill Petrole because he was carrying large amounts of cash and marijuana, believing if they only robbed Petrole he would seek revenge.

At trial in 2002, Barber testified that he shot Petrole at Wolfe’s request and received a plea deal with a lesser murder charge and a 38-year sentence. A jury convicted Wolfe and sentenced him to death.

But in 2011, a federal judge in Norfolk ordered a new trial for Wolfe, ruling that Prince William prosecutors withheld evidence from the defense, including a police report stating that a detective suggested to Barber that he claim that Wolfe ordered the murder as a way for Barber to escape the death penalty. Barber has subsequently recanted that testimony, then later reversed himself and said Wolfe did order the murder. Most recently, Barber testified to the Norfolk judge that Wolfe did not order the killing.

In 2012, a federal appeals court in Richmond affirmed the order for a new trial, saying that the conduct by Prince William Commonwealth’s Attorney Paul B. Ebert and top assistant Richard A. Conway was “not only unconstitutional in regards to due process, but abhorrent to the judicial process,” noting that withholding the police report and other exculpatory materials “was entirely intentional.”

The Prince William prosecutors then recused themselves and asked that Fairfax County Commonwealth’s Attorney Raymond F. Morrogh be appointed, which a Prince William judge did without notice to Wolfe’s lawyers. Later in 2012, Morrogh obtained six more indictments against Wolfe, in addition to the original three charges against him, adding two more murder charges and two more gun charges.

Then in March 2016, Wolfe pleaded guilty to first-degree felony murder, use of a firearm and one drug conspiracy charge, in an agreement where he faced a range of 29 to 41 years in prison, with credit for the 15 years he had already served. The handwritten confession Wolfe filed with the plea stated that he and Barber plotted together to kill Petrole, and “I am responsible for Danny’s death even though I didn’t pull the trigger. If I had not been involved Danny would never have been killed.” Wolfe had previously maintained his innocence. He was sentenced to 41 years in prison.

Wolfe’s new lawyer, Marvin D. Miller of Alexandria, argued to the Supreme Court that Wolfe entered his plea because he faced the possibility of another death sentence and concluded that “the Commonwealth was determined to deny him a fair trial.” Miller’s brief said the Prince William trial court “erred in accepting his guilty plea because he was the target of a vindictive prosecution” after Wolfe won relief from the federal courts.

Both the Virginia Court of Appeals and the Virginia Supreme Court rejected Wolfe’s appeals last year, saying he waived his right to appeal the issue because he pleaded guilty without any conditions allowing for such appeals.

Miller took the case to the Supreme Court. Meanwhile, the high court ruled last February on the case of Rodney Class, who was charged with possessing firearms in his locked jeep on the grounds of the U.S. Capitol. He pleaded guilty, but appealed on the grounds that the law under which he was convicted was itself unconstitutional under the Second Amendment. A federal appeals court rejected Class’s claim, but the Supreme Court granted Class’s right to a hearing because of his constitutional claim.

“Does a guilty plea bar a criminal defendant,” Justice Stephen G. Breyer wrote, “from later appealing his conviction on the ground that the statute of conviction violates the Constitution? In our view, a guilty plea by itself does not bar that appeal.” Breyer cited a North Carolina case in which a man was convicted of a misdemeanor, appealed, and then was charged by prosecutors with a felony. He pleaded guilty but appealed, claiming vindictive prosecution, and the Supreme Court ruled he could do so.

In Wolfe’s case, the Supreme Court did not issue an opinion but instead merely vacated the Virginia Supreme Court’s ruling and ordered the case back to the Commonwealth for argument on the merits of Wolfe’s claim. It is not clear if Virginia’s Supreme Court would then return the case to the state appeals court for that hearing to happen.

“This is an extremely rare type of case,” said Miller, Wolfe’s lawyer, “where there is a serious question of the authority of the court to even entertain the case at all.” He said the prosecutorial misconduct cited by the federal courts who first overturned the case, compounded by the additional charges filed by the new prosecutor, “are of such a degree that the court doesn’t have authority to proceed.”

Morrogh, the Fairfax prosecutor who took over the case in 2012, said, “There is absolutely no place in the criminal justice system for vindictiveness and there was none here. I sought the truth and only the truth.” Morrogh was not involved in the appeals, which are handled by the Virginia attorney general, but he said after he joined the case he studied the evidence and “I concluded that the defendant was, in fact, not innocent. The defendant acknowledged his guilt, of his own accord, when he made a handwritten confession and pleaded guilty in court.”

The Virginia Office of the Attorney General and Prince William prosecutor Ebert declined to comment Tuesday.