Investigators would not comment on a motive for the attack.
John Odgren, 16, pleaded not guilty in the killing of 15-year-old James Alenson and was jailed without bail.
Odgren's attorney, Jonathan Shapiro, said Odgren has Asperger's syndrome, a form of autism, and has been taking medications for many years.
"The defendant has a history of fairly serious psychological diagnoses and has also suffered from hyperactivity dysfunction for many years," Shapiro said. "What is clear is John has a serious disability."
The two boys got into a fight in a bathroom, and it spilled out into a hallway at Lincoln-Sudbury Regional High, authorities said. Odgren stabbed Alenson twice with a long knife once in the abdomen and once in the heart, prosecutor Daniel Bennett said.
"The timing of the stabbing strongly suggests that Mr. Odgren planned this premeditated murder," Bennett said.
Odgren blurted, "I did it" to police moments after the stabbing, and also said: "Is he OK? I don't want him to die," according to authorities.
All 1,600 students at the school about 17 miles west of Boston were sent home.