Updated

A 23-year-old gunman opened fire at a public elementary school in Rio de Janeiro on Thursday and killed at least 11 students before killing himself.

Earlier, police said at least 13 people died in the shooting, but Rio state Health Secretary Sergio Cortes said 10 girls and one boy were killed, along with the gunman. The ages of the children were not immediately known.

Cortes said at least 18 other people, mostly students, were hurt and brought to local hospitals. At least four were in grave condition.

Officials said the gunman was a former student at the Tasso da Silveira school, located in a working-class neighborhood in western Rio. A motive was not immediately known, but authorities said the man 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.

More On This...

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 (7:30 a.m. EDT; 1130 GMT). 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 located the gunman on the second floor and traded shots with him.

"He saw me and aimed a gun at me," said officer Marcio Alves. "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 kids 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."

Based on reporting by the Associated Press.

Follow us on twitter.com/foxnewslatino

Like us at facebook.com/foxnewslatino