Thirty of their classmates and eight adults are still missing in the building, which like dozens of others has been turned into rubble.
Two adults were also killed when the primary school Colegio Enrique Rebsamen collapsed in Mexico City, said the country’s President Enrique Pena Nieto, who visited the scene.
The 7.1 magnitude quake hit central Mexico hours after preparation drills were held on the anniversary of a devastating 1985 earthquake that killed more than 5,000 people in Mexico City.
At least 216 people have been killed in Tuesday’s quake, including 117 in the capital, authorities confirmed.
At the school, TV pictures showed rescue teams working late into the night, using picks, shovels and their hands as well as heavy lifting gear in an attempt to find survivors.
Education officials said 25 bodies had been recovered but three were pulled out alive.
Relatives said they had received a WhatsApp message from two girls inside.
“They keep pulling kids out, but we know nothing of my daughter,” said 32-year-old Adriana D’Fargo, whose seven-year-old remains missing.
President Enrique Pena Nieto, after visiting the school, appealed for calm, saying: “The priority at this moment is to keep rescuing people who are still trapped and to give medical attention to the injured people.”
Earlier, panicked workers fled from office buildings and clouds of dust rose up from the crumbling facades of damaged buildings after the quake struck.
As many as 44 buildings collapsed in Mexico City, according to mayor Miguel Angel Mancera.
The US Geological Survey said the quake was centred near Raboso in Puebla state, 76 miles (123km) southeast of Mexico City.
Officials asked people not to smoke in the streets of Mexico City – which has a population of 20 million – warning of possible ruptured gas pipes.
Mexico City International Airport suspended operations, while electricity and phone lines were down in parts of the capital.
The earthquake came less than two weeks after an 8.1 magnitude tremor in southern Mexico killed at least 98 people.