HELENA, Mont. (AP) — The Montana Supreme Court has ruled a fellow justice illegally accepted a "no contest" plea while overseeing a sexual assault case in 2015.

Justices vacated Gary Hansen's 60-year prison sentence for raping an 8-year-old girl in 2006 and sent the case back to District Court in Great Falls where Hansen can enter a legal plea, reach a new plea agreement or take the case to trial.

The justices, in a Nov. 14 opinion, found then-District Judge Dirk Sandefur violated a state law that prohibits "no contest" pleas in cases involving sexual offenses. Hansen, who is now 61, was charged in in 2013. The plea agreement was reached in June 2015, just before his trial was to begin.

Sandefur was sworn in as a Supreme Court justice in January 2017.