The gunman killed one police officer and one biology teacher, police said. Another policeman was shot and injured.
The hostages the gunman took have been released, police said.
The incident, on the outskirts of Moscow, comes as Russia prepares to host the Winter Olympic Games, due to start in Sochi this week.
The gunman is believed to be a pupil at School No. 263 on the northern outskirts of Moscow.
“The person who took 20 people and a teacher hostage is a student in the upper classes at the same school,” an interior ministry spokesman said on state TV.
“He has been neutralized and all the students have been freed,” he said.
“One policeman was fatally wounded during the operation and died in hospital, and a teacher at School No. 263 was also killed,” he added.
It is not clear how the teacher and the policeman died.
A school official told Russian television that all children and teachers had been evacuated from the school after the incident.
The gunman opened fire on police officers who arrived at the scene, reports say.
QVk2v-eGPtYThe US House Ethics Committee has voted to release its report on former Republican Representative…
ABC News has agreed to pay $15 million to President-elect Donald Trump to settle a…
South Korea’s parliament has voted to impeach President Yoon Suk Yeol over his failed attempt…
Israeli war planes have carried out more than 100 air strikes in Syria on December…
President-elect Donald Trump has threatened to impose 100% tariffs on the BRICS countries if they…
Syrian troops have withdrawn from the city of Aleppo following an offensive by rebels opposed…