A teenager described as a model student has shot a teacher and a police officer dead and took more than 20 of his schoolmates hostage in a classroom, days before Russia hosts the Winter Olympics under tight security.
The suspect was disarmed and detained about an hour after the shootings on Monday (local time) after talking to his father, the owner of the two rifles with which he forced his way into the school in northern Moscow at midday.
The incident rattled nerves in a country on high alert for Islamist militant violence as athletes and spectators arrive for the Sochi Games, a prestige project that will help shape President Vladimir Putin's legacy.
Putin, who says young Russians are suffering from a moral vacuum left by the collapse of the Soviet Union in 1991, said the attack might have been avoided with better cultural education.
It is almost unheard-of for a student to attack a school in Russia. A horrific assault in 2004 on a school in Beslan in the North Caucasus, in which more than 330 people were killed, was the work of Islamist separatists.
Investigative Committee spokesman Vladimir Markin said the Moscow student may have suffered an "emotional breakdown".
The attacker knocked on the door of the 10th grade (equivalent to year 11 in New Zealand, students 15-16 years) class about five minutes after the start of a lesson, his classmate Ivan Chekanov, one of the students who was held hostage, said.
"We were glad to see him at first - but then he shot the geology teacher," Chekanov, 16, said. "He fired the shot, then he got up onto the podium, laid out his rifles and said he had 100 bullets and that he had come to die."
"Andrei Nikolayevich (the teacher) was dripping with blood, he had fallen but he was still alive," he said. (The attacker) asked us: 'Why is he still alive? I killed him.' Everyone was silent."
"He said, 'Well, guys, your answer gets a 'D', and fired several more shots," Chekanov said.
The shooting sent dozens of other students scurrying into the street in sub-zero temperatures while a police helicopter landed in a snow-covered field outside and at least six ambulances rolled up to the scene.
Officials said the assailant had also shot a policeman responding to the incident, who died in hospital, and that another policeman had been wounded.
The incident began around noon when the attacker cocked a gun at a guard who tried to stop him entering the school, the federal Investigative Committee said.
It said the guard had managed to press an alarm button, bringing police to the school. "When the police entered, the shooter opened fire at them, wounding one and killing another."
Markin said the assailant fired at least 11 shots.
His father was brought in and spent 15 minutes talking to his son by phone before being given a bulletproof vest and going into the classroom. His son began releasing students 30 minutes later, Moscow police chief Anatoly Yakunin said.
"Once all the students were released and he was alone with his father, special forces ... seized the moment and the 10th grader was neutralised and detained," Yakunin said at the scene.
The attacker had phoned his mother from the classroom, Chekanov said. "Then his father called, and he told him where the geography room was, and to come unarmed."
"His father asked him what he done, where he had got the rifle," Chekanov said. "He got the weapons at home and he got the ammunition from the dresser or the cabinet - he answered something like that."
A former classmate, Sakhobudin Tagoyev, said the alleged attacker was a model student who in the past had "set an example for the whole school".
"The teachers liked and respected him," Tagoyev said. "He was like Einstein."
But Tagoyev also said the alleged attacker was quick to get nervous "if something did not work out for him ... or if he got bad grades".
Russian media said the alleged assailant might have been settling a score with the geography teacher. But Markin said there were "no serious grounds" to suspect the attack was the result of a personal conflict.
Putin told a meeting of a Kremlin advisory council on the arts and culture in Pskov that "the new generation of audiences needs to be raised with good artistic taste and the ability to understand and value the theatrical, dramatic and musical arts".
"And if this was done as it should be in our country, then maybe there would not be tragedies like the tragedy in Moscow today."