A 15-year-old student opened fire with a gun at a private school in the northern Mexican city of Monterrey hitting a teacher and two other students in the head before killing himself.
Another student suffered lesser injuries in the shootings, which were captured on a chilling video posted to social media.
Nuevo Leon state Governor Jaime Rodriguez said the shooter died at a hospital and that the other three victims with head wounds were "fighting between life and death".
The boy wounded in the arm was out of danger.
A video, apparently from the school's surveillance camera, shows a female teacher handing out materials and students seated at their desks when a boy opens fire with a pistol from a sitting position, hitting a boy sitting in front of him, who immediately slumps to the ground.
He next shoots the teacher, who was looking in another direction, and she falls to the ground.
The boy rises from his seat and walks around, firing shots at his classmates, before turning the gun on himself.
His first shot apparently misses his head, and then he runs out of bullets.
The shooter runs to his backpack, apparently to reload, as his classmates cower at their desks.
He appears to say something to the surviving students, who begin to rush for the door, and then he shoots himself in the head and falls to the ground.
The crowded classroom was left with a jumble of overturned chairs, blood and fallen students.
State security spokesman Aldo Fasci said four of the injured, including the shooter himself, had bullet wounds to the head and were in extremely serious condition.
He said the student shot the 24-year-old teacher, a 14-year-old girl and a 14-year-old boy in the head, and a 15-year-old classmate in the arm.
"The classes were going perfectly well, the student stands up from his desk and pulls out a gun," Fasci said.
He noted that photographs of the shooting had been posted to social media and said the person responsible would be punished. He also appealed to the news media to avoid using the images, which show minors.
Fasci said the shooter had been under treatment for depression, but that the motive was under investigation.
Fasci said the boy brought the gun from home but it was unclear how he got the .22 calibre pistol into the school.
Mexico had once had a program to checked book bags at school entrances, but in many places it has fallen into disuse.
"'There was a reason why book bags were checked. I think we are going to have to start doing it again," Fasci said.
Mexico had been largely spared the phenomenon of school shootings that has hit the United States. In one of the few previous incidents, a 13-year-old student shot a 12-year-old classmate in the head at a Mexico City middle school in 2004, seriously wounding her.