Defense attorney Patrick Thomassey has acknowledged Hribal committed the attacks at Franklin Regional High School in Murrysville in April 2014, but he has argued it was fueled by the defendant's mental health problems. A judge must hold a hearing and agree that Hribal was mentally ill at time of the crimes in order to accept the plea.

"It's a way to help people with mental illnesses who are going to be incarcerated," Thomassey said late Friday in explaining the reason for the plea.

"How can I try this case, to be candid about it," he told The Associated Press. "Alex wasn't completely insane at the time of the offense but this enables us to get him some help."

Hribal, who is now 18, is charged with 21 counts each of attempted homicide and aggravated assault, and one count of bringing a weapon to school. He faces potentially decades in prison if convicted, but if the judge accepts the plea, he could wind up serving some or all of his sentence in a mental health facility, Westmoreland County District Attorney John Peck said Friday.

Hribal, who was then 16, used two 8-inch kitchen knives from home to attack his victims in the hallways shortly before classes began. Witnesses have said Hribal walked robotically as he slashed and stabbed his way through the school.

Psychological experts hired by the defense and prosecution have previously testified Hribal was trying to emulate Columbine school killers Eric Harris and Dylan Klebold, who killed 13 people and wounded 24 others before killing themselves at their high school in suburban Denver in 1999. Hribal carried out his attack on Harris' birthday — April 9, 2014 — because school wouldn't have been in session on his preferred date, April 20, 2014, the 15th anniversary of the Columbine massacre, the experts said.

Four of Hribal's victims were critically injured, including one who required a liver transplant, but all survived and have since recovered.

Despite the previous psychiatric testimony, Peck said it's not a foregone conclusion that Hribal was mentally ill.

The earlier testimony about Columbine "would indicate premeditation," Peck said Friday. "He was imitating them, so he had a conscious purpose. His actions would reflect the same ideas that motivated the Columbine killers."

To accept Hribal's plea of guilty but mentally ill, the judge must find that Hribal had a mental defect or illness and lacked the "substantial capacity to either appreciate the wrongfulness of his conduct or to conform his conduct to the law," Peck said.

If the plea is accepted, the judge must then determine whether Hribal was still mentally ill at sentencing. If he is, Hribal could be sent to treatment and then potentially moved to prison when deemed no longer mentally ill, Peck said.

Peck wouldn't say whether he plans to oppose the plea, because he hasn't seen what evidence Thomassey intends to present.