(CNN) -- Thursday's massacre of 11 students at a Brazilian school could have been even worse, were it not for the heroic actions of a military policeman, according to a statement from the Rio de Janeiro state governor's office.
Third Sgt. Marcio Alexandre Alves, 38, and a colleague raced to the Municipal School Tasso da Silveira in Realengo after they were approached by a student two blocks away from the school, who asked them for help, the governor's office said.
Upon arriving at the school, Alves heard gunshots and quickly climbed to the second floor. There, he confronted the heavily armed gunman coming out of a classroom, keeping the suspect from ascending to the third floor, where there were more students, the statement said.
Alves said he shot the gunman in the abdomen. When the suspect fell, he committed suicide by shooting himself in the head, according to the statement.
At that point, Alves looked for a second suspect he had heard was in the building, but that information turned out to be unfounded, the governor's office said.
Alves, an 18-year veteran of police work, said seeing the slain children gave him a great feeling of sadness.
"Scenes that will not be easily erased from my memory. I have a son that age," Alves said. "But it was also a sense of accomplishment. I wish I would've arrived there sooner (to save more children). Had I gotten there five minutes earlier, I could have avoided some deaths," the statement said.
Brazil's president has announced three days of national mourning.
Beyond the 11 students killed, another 13 were injured, four of whom were in critical condition, Rio Health Secretary Sergio Cortes said.
The Rio de Janeiro Civil Police released the names of nine of the massacred students to Agencia Brasil. the official state-run media. They are:
Karine Chagas de Oliveira, 14
Rafael Pereira da Silva, 14
Milena dos Santos Nascimento, 14
Mariana Rocha de Souza, 12
Atanazio Larissa Santos
Bianca Tavares Rocha, 13
Luiza Paula da Silveira, 14
Laryssa Silva Martins, 13
Gessica Guedes Pereira
"The greatest difficulty is the family's pain. It is very hard to identify a son or a daughter in a situation like this," Cortes said. "It's a state of general commotion here, families, doctors, everyone."
Several of the children will be buried Friday at locations and times still to be determined, Agencia Brasil reported.
Municipal School Tasso da Silveira is in the northern Rio neighborhood of Realengo, a middle- and lower-middle-class area located between the Pedra Branca and Mendanha mountains.
The school is now a crime scene, and will remain so for an undisclosed amount of time, police said.
The government said the gunman was Wellington Menezes de Oliveira, 23, a former student at the school. He was allowed to enter the school by saying he was there to obtain transcripts.
According to CNN affiliate TV Record, Menezes de Oliveira entered the school in the morning armed with two handguns and began shooting at children and school personnel. He was firing "indiscriminately," Agencia Brasil said.
There were reports that he had left a letter behind that mentioned he had HIV, Agencia Brasil said. Other details from the letter were not immediately disclosed and the gunman's motive remained unclear.
The Rio government said they found no previous criminal record of Menezes de Oliveira.
An amateur video posted on YouTube showed the police arriving at the school as onlookers watched from the front of the school. Repeated high-pitched screams can be heard as students begin sprinting out of the school in a line. One girl runs by with her shirt stained red around her abdomen. Another has what appears to be blood soaking her shoulder.
The injured were transported to the Albert Schweitzer Hospital, where Agencia Brasil reported helicopters were waiting in an adjacent field, ready to transport the more seriously injured to other facilities. Police used some of those helicopters to move the victims, the government of Rio said.
Rio de Janeiro's Hematology Institute, which coordinates the distribution of blood for transfusions, put out a call via Twitter for donations to the hospital.
Brazilian President Dilma Rousseff said she was "shocked" by the attack and had "great concern" about the incident. She said mass shootings were rare in Brazil.
"It's uncharacteristic for our country to have this type of crime," she said in a speech. "For that reason, I consider that all of us are united in rejecting this type of violence, especially against defenseless children."
Rio's governor, Sergio Cabral, called the gunman a "psychopath."
"I agree that we have an obligation to give solidarity and support to the families of the young victims of this psychopath," he said.
The school where the shooting happened is a public school with about 800 students.
CNN's Rafael Romo and journalists Luciani Gomes and Catalina Arica contributed to this report