Former Penn State president Graham Spanier is shown after a sentencing hearing in 2017. (Matt Rourke/AP)

A day after the child-endangerment conviction of former Penn State president Graham Spanier was vacated by a federal judge, Pennsylvania Attorney General Josh Shapiro vowed Wednesday to appeal the decision.

Spanier, 70, was fired by Penn State in 2011, shortly after the emergence of the child-abuse scandal involving former Nittany Lions assistant football coach Jerry Sandusky. In the following year he was charged with eight counts, including three felonies, of perjury, obstruction and endangering the welfare of children.

Eventually, Spanier was convicted of a single, misdemeanor count of child endangerment, and he was on the verge of reporting to jail for two months when U.S. Magistrate Judge Karoline Mehalchick ruled that 2007 revisions to a Pennsylvania law should not have been applied to actions ascribed to Spanier in 2001.

Claiming that Spanier, while PSU president in 2001, “was personally advised that children were being sexually abused on school property,” Shapiro said in a statement, “Evidence proved he chose not to help the children — but instead to cover up the abuse, despite being well aware of his responsibility as a supervisor.

“In a last-minute and highly unusual decision yesterday evening, a federal magistrate set Spanier free just before he was finally about to begin serving his deserved sentence,” Shapiro continued. “Federal courts have very limited power to act in state criminal proceedings, and this ruling plainly exceeded that power.”

In response, Spanier’s lawyers said in a statement that they were “dismayed” that Shapiro “would blatantly and prejudicially misrepresent facts.” They asserted that “there is no evidence that Graham Spanier was personally advised that children were being sexually abused.”

Spanier and two other Penn State officials, former athletic director Tim Curley and former vice president Gary Schultz, were accused of not taking a 2001 report from another PSU coach, of seeing Sandusky in a shower with a young boy, to police or child-welfare authorities. Spanier said he was unaware of the severity of Sandusky’s behavior and characterized his impression of it at the time as “horseplay.”

During Spanier’s 2017 trial, prosecutors presented a 2001 email from him to Curley and Schultz, after the three administrators agreed to present what they’d learned only to Second Mile, a youth-focused charity tied to Sandusky. Spanier was shown in the email as saying that “the only downside for us is if the message isn’t ‘heard’ and acted upon, and we then become vulnerable for not having reported it.”

Curley and Schultz pleaded guilty to misdemeanor child endangerment in 2017 and served three and two months, respectively, in jail, but Spanier appealed his conviction. On Tuesday, Mehalchick gave prosecutors three months to decide whether to retry Spanier under the 1995 version of Pennsylvania’s child-endangerment law that would have been in place in 2001.

“Spanier submits that this retroactive application is unreasonable and far more extensive than anyone in 2001 would have been able to reasonably foresee,” she wrote in her decision. “The court agrees.”

Shapiro took issue with that ruling, saying in his statement: “As the Pennsylvania Supreme Court has made crystal clear, Spanier’s conduct was illegal. The Office of Attorney General will quickly appeal this ruling to hold him accountable for his conduct covering up child sexual abuse. No one is above the law.”

In the 2017 trial, prosecutors claimed that if Spanier, Curley and/or Schultz — or former Penn State head coach Joe Paterno, for that matter — had gone to the proper authorities with the report of the alleged shower incident, instead of attempting to handle it internally, Sandusky might have been deterred from further abuses of children.

In 2012, Sandusky, then 68, was convicted on 45 counts related to sexually abusing 10 young boys, and he was sentenced to 30 to 60 years in prison. In February, a Pennsylvania court denied his request for a new trial but ordered a resentencing, ruling that the 2012 judicial decision was based on an improper application of mandatory minimums.

Before Mehalchick’s ruling, Spanier was set to begin a two-month term Wednesday in the Centre County (Pa.) Correctional Facility, to be followed by two months of house arrest at his home in State College, Pa. Since being fired as president, according to reports, Spanier has remained a tenured PSU professor on paid administrative leave, with the university obliged by a separation agreement to pay his legal fees.

Read more from The Post:

Former Texas A&M football player convicted of murder in 2015 machete attack

Bruno Fernando will remain in NBA draft, forgoing final two years at Maryland

Court rules Olympic runner Caster Semenya must use hormone-suppressing drugs to compete