The official said two staff and the driver had also died in the crash which happened in Karatu in the north of the country.
Innocent Mushi, director of the Lucky Vincent Primary School, said the dead included 12 boys and 17 girls.
The bus was taking the children from their school in Arusha for an exam on Saturday.
Arusha regional police commander Charles Mkumbo said: “The accident happened when the bus was descending on a steep hill in rainy conditions.
“We are still investigating the incident to determine if it was caused by a mechanical defect or human error on the part of the driver.”
In a statement, President John Magufuli described the accident as a “national tragedy”.
He added: “This accident extinguishes the dreams of these children who were preparing to serve the nation, it is an immense pain for the families involved and for the whole nation.”
Tanzania has a poor road safety network but the bus remains the main mode of transport between towns.
More than 11,000 people died in road accidents in the country between 2014 and 2016, according to government figures.