Gov. Joao Doria says the two attackers were believed to be between 20 and 25 years old. The students who died were boys mostly 15 and 16 years old.
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. "He stopped going to school ... because of this", she said.
He said it was not yet known whether the assailants were former pupils at the school.
Marcelo Salles, commander of police forces in Sao Paulo state, said: "It was an unspeakably brutal crime". Some of them were said to be in critical condition.
The two adolescent attackers, who were wearing face masks, killed themselves after the rampage, officials said.
The public school, Raul Brasil Professor (translated in English), has more than 1,600 students from elementary to high school grades, teachers gathered outside said.
Latin America's most populous nation has the largest number of annual homicides in the world, but school shootings are rare.More news: Trump blasts 'fake news' over Melania body double theory
More news: Viral challenge encourages people to clean up garbage
More news: Lady Gaga Tackles Pregnancy Rumors Head On
The last one occurred in 2011, when the former student of a school returned and shot 12 children fatally, Fox News reports.
The attack comes after Brazilian President Jair Bolsonaro announced that the country's gun ownership controls would be eased.
It's not the first mass school shooting in Brazil's history. It was not immediately clear whether the two incidents were linked.
She managed to escape, and students frantically scrambled out of the school. "I put my cell phone into his hand and he typed, with his dirty hands trembling, that he wanted me to call his mom", Gonçalves said.
The attack took place at around 9:30am during a recreation period for some students, authorities said.
Students gathered outside the school recounted harrowing attacks and seeing several bodies lying in pools of blood.
São Paulo state governor João Doria tweeted that the victims had been "cruelly murdered".