The gunman was identified as a 23-year-old former pupil. Another 18 people were also injured in the shooting.
Globo TV showed images of the victims being taken away by ambulance from the Escola Municipal Tasso da Silveira school in the western Realengo area.
Brazilian President Dilma Rousseff later said she was "shocked" by the massacre.
"Innocent children lost their lives and their future," she said, after observing a minute of silence for the victims.
'Aiming at heads'
"The person entered, and fired shots," a spokeswoman for Rio's police told Globo. The attacker - who was later identified as Wellington Menezes Oliveira - entered the school at about 0830 local time (1130 GMT).Globo said he had told school officials he was there to make a speech.
He reportedly had two revolvers and a lot of ammunition. He opened fire aiming at victims' heads, killing 10 girls and a boy.
It is still unclear whether the gunman then shot himself or was killed by the police, who arrived at the scene.
Officials earlier said that 12 pupils and the gunmen had died in the shooting and at least 20 people had been injured.
'Desperate and crying' Dorival Porto Rafael, a rubbish collector who was at the school at the time, told Globo online that the gunman walked into a class where students were studying Portuguese.
"He came into the class saying he was going to give a talk. He went to an eighth-grade class, on the [ground floor], and without saying anything took out a pistol from his bag and started firing," Mr Rafael said.
"The police arrived and he tried to go up to the next floor, but when he saw he was surrounded he shot himself in the head," the eyewitness added. The BBC's Paulo Cabral says hundreds of people are gathered outside the school
Rodrigo Alves Pereira, who lives in the area, told the BBC that he was in a shop near the school when he heard "a lot of shots coming from inside the school".
"I went out and saw many children... coming out of the school. Some of them were covered in blood, shaken, asking for help. One was injured in the shoulder. They were desperate and crying.
"They said that there was a man wearing a suit who was shooting at school kids in classrooms. He first went to a reading room, talked to teachers there, and then went on to two classrooms. This is a complete tragedy. We are all devastated," Mr Pereira said.
Police later said the gunman had a letter, stating that he intended to commit suicide after the shooting. Media reports suggested he had Aids.
Rescue workers used a football pitch near the school as a helicopter base from which to transport wounded children to the hospital.
Hundreds of people gathered outside the school, either out of curiosity or to check on children who were inside at the time of the shooting, the BBC's Paulo Cabral in Rio de Janeiro says.
The school in Rio's impoverished neighbourhood is attended by pupils aged nine to 14.