A federal judge in Pennsylvania threw out former Penn State University president Graham Spanier's conviction on a child endangerment charge Tuesday, the day before Spanier was due to report to prison.

Spanier was found guilty in 2017 of a misdemeanor count related to his handling of a 2001 complaint about longtime Nittany Lions assistant football coach Jerry Sandusky showering with a young boy at the football facility. He was sentenced to a minimum of two months in jail and two months of house arrest and a state judge had ordered him to report to jail May 1.

However, U.S. Magistrate Judge Karoline Mehalchick agreed with Spanier's argument that he had been improperly charged, writing: "the conviction in this matter was based on a criminal statute that did not go into effect until six years after the conduct in question [in 2001], and is therefore in violation of Spanier’s federal constitutional rights."

Mehalchick's ruling gave state prosecutors three months to retry Spanier. A spokesman for Pennsylvania Attorney General Josh Shapiro told Penn Live that prosecutors had "received the court's opinion and are reviewing it."

Spanier had served as Penn State president for 16 years until he was forced out following Sandusky's November 2011 arrest on more than three dozen charges of sex crimes against young boys. He was charged the following year with grand jury perjury, obstruction of justice, child endangerment, failure to report child abuse and conspiracy, though many of those counts were thrown out prior to trial.

Two high-ranking administrators under Spanier, former athletic director Tim Curley and former vice president Gary Schultz, pleaded guilty to child endangerment on the eve of trial and testified against him.

CLICK HERE TO GET THE FOX NEWS APP

The state Supreme Court in February declined to take up Spanier's appeal of his conviction, prompting his bid to vacate the conviction.

Sandusky, a longtime assistant to legendary Penn State football coach Joe Paterno, was convicted and sentenced to between 30 and 60 years in state prison. In February, a Pennsylvania appeals court ordered that Sandusky be resentenced, ruling that the original sentence was based on the improper application of mandatory minimums.

The Associated Press contributed to this report.

Click for more from PennLive.com