Pupils cowered in fear and pleaded for their lives as a 12-year-old boy went on a rampage with a handgun, waving the weapon at classmates and shooting dead a maths teacher.
The boy opened fire on Monday morning at Sparks Middle School in Nevada, wounding two boys and killing the teacher on a basketball court before he turned the gun on himself.
Washoe County School District police said the seventh-grade pupil brought the 9mm semi-automatic Ruger gun from his home, but authorities were still working to determine how he obtained it. The boy's parents were co-operating with authorities and could face charges, police said.
The community was left struggling to make sense of the latest episode of school violence to rock the United States less than a year after the massacre in Newtown, Connecticut, left 26 dead. That shooting reignited debate over gun control and how best to protect schools in particular.
Eighth-grader Angelo Ferro said he buried his face in his hands and pleaded for his life as the boy waved the gun and threatened to shoot. Another boy and Angelo's maths teacher, Michael Landsberry, lay gunned down nearby.
"The whole time I was hoping Mr L was OK, we'd all get through it, it was a bad dream," Angelo, 13, said.
Angelo said was in the playground with friends when the violence started. He heard a pop about 15 minutes before the morning bell rang but did not think much of it. Then he saw an injured boy clutching a wounded arm, and he watched Mr Landsberry walk towards the gunman and be fatally shot in the chest.
Unable to get inside the locked-down school, Angelo and others crouched against the building for safety but soon came face-to-face with the armed boy.
He did not know the boy and said he and other frightened classmates tried to talk him out of firing. Then something distracted the boy and he did not shoot.
"You could hear the panic," Angelo said. "He left, thank God."
A series of emergency calls made from the school also reflected the terror of the situation, including an ominous report of "teacher down".
"Can you send please send police out here," a panicked pupil told a dispatcher. "There's a kid with a gun."
Authorities, who are not naming the boy out of respect for his family, provided no motive for the shooting but said they had interviewed 20 or 30 witnesses and were looking into any prior connections between them and him.
"Everybody wants to know why - that's the big question," Sparks deputy police chief Tom Miller said. "The answer is, we don't know right now."
Under Nevada law it is illegal to allow anyone under 18 to handle a gun without supervision. The offence rises to a felony if there was substantial risk the child would use the firearm to commit a violent act. But the law does not apply if the gun was stored securely or if the child obtained the weapon unlawfully.
Meanwhile law enforcement and school officials lauded the actions of Mr Landsberry, 45, a former US Marine, who tried to stop the rampage before he was killed.
"I cannot express enough appreciation for Mr Landsberry," Washoe County School District Superintendent Pedro Martinez said. "He truly is a hero."
Students said they saw Mr Landsberry walk calmly towards the boy and ask him to hand over his weapon before he was killed. School district police chief Mike Mieras said Mr Landsberry's actions gave some pupils enough time to run to safety.
Police said they believe the shooter at one point tried to enter the school but could not open the door because of emergency lockdown procedures.
After killing Mr Landsberry, he fired at a second student, hitting him in the stomach. He then shot himself in the head.
The two 12-year-old boys who were wounded are in a stable condition.
Pupils from the middle school and neighbouring primary school were evacuated to a high school after the shooting and all classes were cancelled. The middle school will remain closed this week.
Sparks, just east of Reno, has a population of roughly 90,000.
"Every one of the people I have talked to just knew that Mike was in there," he said. "He was the guy that would have jumped in there to stop the bullets from hitting other kids. And sure enough, it was."