The student, who had two rifles and fired at least 11 shots, was disarmed and detained less than two hours after the shooting in northern Moscow following negotiations aided by his father. There were reports he might have been seeking revenge over a conflict with a teacher.
Investigative Committee spokesman Vladimir Markin said the teenager may have suffered an "emotional breakdown" when he entered the school with two of his father's rifles and shot a geography teacher several times.
Ivan Fodokin, 17, a student at School No. 263, said: "We were in the stairwell when we heard the man outside yelling to the police officer to open the door, and then we heard shooting."
A guard tried to stop him getting into the school and managed to press an alarm button, bringing police to the school.
The shooting sent dozens of 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 went to the scene.
The shooting could rattle nerves at a time when athletes and spectators are arriving for the Sochi Games and the country is on high alert over an Islamist militant threat of violence.
State-run media tend to portray school attacks as a largely American phenomenon and they are rare in Russia.
However, separatist militants seized a school in the North Caucasus town of Beslan in 2004. More than 330 people, mostly children, were killed.