Former New England Patriots star Aaron Hernandez is no longer a convicted murderer because he hanged himself in prison last month before his appeal could be heard, a judge ruled Tuesday, citing a Massachusetts legal doctrine.

A state law says murder convictions are abated — effectively erased — after an inmate’s death if the inmate’s appeals options have not been exhausted.

“Abatement remains the law in this Commonwealth and this court is compelled to follow’’ that legal precedent, Superior Court Judge E. Susan Garsh said, The Boston Globe reported.

Garsh vacated Hernandez’s first-degree murder conviction for the 2013 shooting of semi-professional football player Odin Lloyd because his trial had not been reviewed by the Supreme Judicial Court before his April 19 death.

The former tight end hanged himself in his prison cell while serving a life sentence on a first-degree murder conviction, officials said. He died five days after being acquitted in a separate double slaying in 2012.

The judge also said prosecutors did not convince her that Hernandez’s death at the Souza-Baranowski Correctional Center was a voluntary act only aimed at having the conviction thrown out.

She said his death involved a series of complex issues, including possible “mental disturbance” — as well as concerns about media reports that he was gay that were released a day before his death.

Garsh also said the Supreme Judicial Court has remained resolute in supporting the legal principle known as abatement ab initio — Latin for “from the beginning” — and that she would not make a ruling that contradicted the state’s highest court.

Bristol Assistant DA Patrick Bomberg earlier told Garsh “this is not a defendant who has arrived at the killing of himself by happenstance. The defendant should not be able to accomplish in death what he couldn’t accomplish in life.”

But Hernandez’s court-appointed appellate attorney, John Thompson, told the judge that the state’s highest court has applied the legal doctrine “without exception,” even in cases of suicide.

“This is an established common-law doctrine,” he said.

The attorney also said a probe is ongoing about whether Hernandez killed himself and, if he did, whether he even knew about the legal doctrine.

Bristol District Attorney Thomas Quinn III has argued that a defendant’s death while an appeal is pending does not always require an abatement — including when “a defendant’s death is a result of his own conscious, deliberate and voluntary act.”

Garsh announced her decision from the bench as Lloyd’s mother, Ursula Ward, sat in the courtroom.

Also in the courtroom was Shaneah Jenkins, Odin Lloyd’s girlfriend at the time of his murder.

Her twin sister, Shayanna Jenkins Hernandez, is the longtime fiancée of Hernandez and the mother of their 4-year-old daughter.

With Post Wires