First responders and local residents rushed to the scene to help rescue people. At 10 a.m., three more powerful explosions occurred, killing some of those who had come to help, the government statement said.
Firefighters, local and state police and civil defense workers were among those injured, the statement said.
Mexico State civil defense said 17 people died at the scene and seven died later at hospitals.
Helicopters took the wounded to several local hospitals, and more than 300 police were dispatched to the scene.
Luis Felipe Puente, head of Mexico's civil defense agency, said there were four blasts in total and the explosions started at an unauthorised, clandestine workshop and spread as flammable material shot into the air. He said the dead also apparently included one minor and a civil defense worker.
"The problem was that after the first explosion, people went running to help, and when the second explosion occurred, these people who ran to help were killed," Puente told the Milenio news network.
Many residents in the town make a living by fabricating and selling homemade fireworks, and explosions are a regular occurrence.
But authorities have been unable to enforce safety regulations and registration requirements.
"We cannot continue to allow this kind of situation," Puente said.
In June, seven people were killed and eight injured in a blast in Tultepec.
In December 2016, a massive fire at an open-air fireworks market crowded with holiday shoppers killed several dozen people.
Deadly fireworks explosions have also occurred elsewhere in Mexico. In 2002, a blast at a market in the Gulf coast city of Veracruz killed 29; in 1999, 63 people died when an explosion of illegally stored fireworks destroyed part of the city of Celaya; in 1988, a fireworks blast in Mexico City's La Merced market killed at least 68; and in 2013, a rocket struck a truck loaded with fireworks for a religious procession in Tlaxcala state, killing 17 people.
Safety measures at fireworks workshops and markets have been a matter of constant debate in Mexico.
While regulations exist on the books, many continue making powerful firecrackers and bottle rockets and selling them to the public.
- AP