Two armed attackers wearing face masks have stormed a Brazilian high school and killed five students, a teacher and an administrator before turning their guns on themselves.

Key points: The attackers, aged 17 and 25, were already dead when police arrived less than 10 minutes after the rampage began

The attackers, aged 17 and 25, were already dead when police arrived less than 10 minutes after the rampage began They had been trying to force their way inside a room at the back of the school where many students were hiding

They had been trying to force their way inside a room at the back of the school where many students were hiding One of them had posted 26 photos on his Facebook page, included several with guns, minutes before the attack

Eight people in total were killed by the attackers, Sao Paulo police said, adding that they had been identified as former students of the Raul Brasil school.

Before launching their attack, Guilherme Taucci Monteiro, 17, and 25-year-old Henrique de Castro shot and killed the owner of a used car business near the school, authorities said.

Nine others were wounded in the school attack and taken to hospital, said Joao Camilo Pires de Campos, the state's public secretary.

During the attack, Monteiro opened fire with a handgun and de Castro used a crossbow, Mr de Campos said, adding that forensics would determine how each of the victims died.

The attackers were also carrying homemade bombs, knives and small axes.

Security cameras showed students jumping over a wall around the school and sprinting away screaming for help. ( AP: Mauricio Sumiya )

Kelly Milene Guerra Cardoso, 16, said she and other students took refuge in the school's cafeteria, locking the door and lying on the floor.

"We stayed there until the door was opened," she said.

"We thought it was the shooters coming to get us, but it was the police.

"They told us to start running."

The attackers were trying to force their way inside a room at the back of the school where many students were hiding when police arrived.

Instead of face police, they turned their weapons on themselves, authorities said.

Police said nine people were wounded in the attack. ( AP: Johnny Morais )

Mr de Campos said police did not know why the pair attacked the school.

Minutes before the attack, Monteiro had posted 26 photos on his Facebook page, included several with guns and one that showed him making an offensive hand gesture as he looked into the camera.

In some of the photos, he wore a black scarf with a white imprint of a skull and cross bones.

No text accompanied the posts.

By Wednesday afternoon, Facebook had taken down Monteiro's page.

'Unspeakably brutal crime'

Marcelo Salles, commander of police forces in Sao Paulo state, said it was a "horrendous" scene.

"In 34 years as a policeman, it's the first time [I've seen] someone use a crossbow like that," he said.

"It was an unspeakably brutal crime."

A homemade video taken during the shooting and aired by Globo TV showed children screaming, running and begging for their lives as loud shots were heard all around.

Security cameras from homes near the school showed children jumping over a white wall that surrounds the Raul Brasil building and sprinting down streets, screaming for help.

Police officers were on the scene eight minutes after the shooting began. ( AP: Mauricio Sumiya, Futura Press )

School shootings are rare in Brazil, even though the country is one of the world's most violent, with more annual homicides than any other.

The last major school shooting was in 2011, when 12 children were shot dead by a former pupil in Rio de Janeiro.

While gun laws are extremely strict in Brazil, it is not difficult to illegally purchase a weapon.

"Our solidarity goes out to the families of the victims," Sao Paulo Governor Joao Doria said as he stood outside the Raul Brasil school.

"I was shocked with the scenes I saw inside that school. It is the saddest thing I have seen in my life."

AP/Reuters