Story highlights Student said to have had issue with geography teacher, state news channel reports

A police officer and teacher were killed in the attack

The gunman, said to be a student at the Moscow school, has been detained

All of the hostages have been released; about 20 students were held, state media says

A Moscow high school student shot a teacher and a police officer dead and held about 20 other pupils hostage in a classroom Monday before he was disarmed and detained, Russian authorities said, just days before Russia hosts the Winter Olympics.

In a rare school shooting in Russia, the attacker entered his school in northern Moscow with a rifle and held students and a teacher hostage in a biology classroom, the Investigative Committee of Russia said.

The incident, at School No. 263, happened around noon local time when the armed student forced his way past a security guard, who raised an alarm.

"On his way to the class the shooter injured one of the teachers who died later," said the committee, Russia's federal intelligence agency. "The police officers arrived to the school. When they entered the building the shooter opened a gun fire, injured one and killed another."

All of the hostages were released and the gunman was detained, it added.

JUST WATCHED Report: 2 dead in school shooting Replay More Videos ... MUST WATCH Report: 2 dead in school shooting 01:18

State media said there were about 20 students in the classroom.

The incident comes as Russia prepares to host the Winter Olympic Games, due to start in Sochi this week.

Motive unclear

State news agency RIA Novosti said it was unclear what motivated the attack.

State news channel Russia 24 said the student is said to have had an issue with a geography teacher. This was not the teacher who was shot or who was among the hostages, it said.

He is also said to have been an "A" student, state media reported, adding that his apartment is being searched by investigators.

Television footage showed the school building surrounded by police and fire emergency vehicles.

An Emergencies Ministry helicopter landed near the school and evacuated the injured police officer, Russia 24 said.

The media outlets said the student had a small-bore rifle and a hunting carbine, which were registered under his father's name.

They reported he is said to have fired 11 times. His father called him and spoke to him for 15 minutes to try to convince him to release his hostages. The father then went to the school and talked to the student in the classroom. Only then did he agree to release his hostages, state media said.

CNN could not immediately independently verify this.

Olympics are days away

The shooting came as the global spotlight falls on Russia, which will host the 2014 Winter Olympics in four days.

Security concerns have been heightened after twin bombings in Volgograd in December.

The Olympic Games will begin Friday in Sochi, and a huge security operation is under way around the Black Sea resort city.

Russia is pouring resources into ensuring that the Olympic Games, seen as a flagship project of President Vladimir Putin, go off without problems.