At least 18 other people, mostly students, were hurt and brought to local hospitals, said Rio state Health Secretary Sergio Cortes. At least four were in grave condition.
The dead included 10 girls and one boy, plus the gunman, Cortes said. The ages of the children were not immediately known. Police had said earlier that at least 13 people had died in the shooting.
A police spokeswoman said the gunman was identified as 23-year-old Wellington Oliveira, a former student at the Tasso da Silveira school, in a working-class neighborhood in western Rio. She spoke on condition of anonymity, saying she was not authorized to discuss the matter.
A motive was not immediately known, but authorities said the shooter left a rambling and mostly incoherent letter at the scene indicating he wanted to kill himself.
Rio is a city rife with drug-gang violence in its vast slums, but school shootings are rare. The gunman had no criminal history, police chief Martha Rocha told a news conference.
Rocha said he walked into the school with two firearms -- she didn't detail what type -- and an ammunition belt. He fired off at least 30 rounds.
About 400 people were inside the school when the shooting began about 8:30 a.m. local time. The school serves grades one through eight.
Two young boys, at least one with a gunshot wound, ran up to two police officers on patrol about two blocks away from the school as the shooting started.
The two officers sprinted to the school and at least one quickly found the gunman on the second floor and traded shots with him.
"He saw me and aimed a gun at me," officer Marcio Alves said. "I shot him in the legs, he fell down the stairs and then shot himself in the head."
Rio Mayor Eduardo Paes said life at the four-story, pastel-yellow-and-green school was turned into a "hellish nightmare."
"This day would have been so much worse if it weren't for the hero policeman," Paes told reporters at the school.
Authorities closed the school temporarily while they investigate, but Paes said it would reopen.
Rio Gov. Sergio Cabral called the shooter a "psychopath." He said there were no indications yet that anyone else was involved in the shooting, but that the investigation would continue.
"We have to investigate where he got the weapons and where he learned to use them," the governor said.
Terrified parents rushed to the school in the Realengo neighborhood. Television images showed them crying and screaming for information about their children.
Zilda Nunes, 67, lives across the street from the school and said three of her grandchildren were inside when the shooting began.
She screamed for help when she heard the gunfire, but didn't enter the building. As students fled, she offered them sugar water to help calm them down, she said.
"There were so many children shot, so much blood," Nunes said. "People were asking for help, but what could I do?"
Wanderson Barbosa, an 11-year-old student at the school, said he was in his classroom when he heard a commotion. He thought students elsewhere were fighting, but said his teacher told the children to lie down on the floor because there was gunfire.
"I'm so worried. We don't have news of everybody yet," said Barbosa, as he sat in his house across the street from the school.
Three helicopters were landing and taking off from a football field next to the school, ferrying the wounded to nearby hospitals.
Brazilian President Dilma Rousseff, attending an event in the capital, Brasilia, lamented the deaths of "defenseless children."
"I ask for one minute of silence for these children who were taken so early from their life," she said, her voice cracking and eyes welling with tears. "It's not in the nature of our nation to have these types of crimes."
Associated Press writers Bradley Brooks and Stan Lehman in Sao Paulo contributed to this report.