A girl who stabbed a classmate in a wooded area near Waukesha has been ordered to 40 years under state mental health supervision. That's the maximum sentence.

Morgan Geyser was found not guilty by reason of mental disease for the crime that has come to be known as the "Slender Man" stabbing.

The court on Thursday ordered Geyser to the Winnebago Mental Health Facility, saying, "conditional release would pose a significant risk of bodily injury to the defendant or others."

Geyser, now 15, cried during the judge's ruling.

She may not have to spend the entire sentence in an institution, according to WISN reporter Nick Bohr. Geyser will be able to ask for a less restrictive setting, depending on her progress.

Geyser's attorney says she can petition to get out of the institution every six months.

"She has a condition she didn't choose to have. It's a hereditary genetic condition that she's cursed with and I think she deserves a lot of credit because at a very young age she's done a lot to address it," said Tony Cotton, Geyser's attorney.

During Thursday's hearing, a psychologist testified that Geyser has a high IQ, but also suffers from schizophrenia that could last through her lifetime.

A psychologist who examined Geyser last October said she still has auditory hallucinations.

Geyser and Anissa Weier were 12-years-old when they were arrested for the stabbing of classmate Payton Leutner.

The stabbing happened May 31, 2014, as the three girls had a sleepover. Investigators said Geyser and Weier lured Leutner to a wooded area with the intent to kill Leutner. Geyser stabbed Leutner 19 times and the girls left Leutner for dead.

Leutner crawled out of the woods. She survived.

Geyser apologized to Leutner and the family during the sentencing hearing, saying "I hope she's [Payton Leutner] doing well."

The girls told authorities that they hoped to win favor with a fictional horror character known as Slender Man. The girls said they had planned the attack for months.

Anissa Weier was sentenced to 25 years in a mental health institution.

On Friday, Feb. 2, ABC 20/20 will air a special on the Slender Man case.

The hour-long program anchored by David Muir includes interviews with mothers Angie Geyser and Kristi Weier; a forensic psychologist; and prosecutor Kevin Osborne.

ABC 20/20 airs at 9 p.m. CT on WBAY-TV 2.