The conflagration in the Mexico City suburb of Tultepec set off a quick-fire series of multicolored blasts that sent a vast cloud of smoke billowing over the capital.

The market had been packed with customers buying pyrotechnics for traditional end-of-year festivities. Christmas and New Year parties in many Latin American countries often wrap up with clattering firework blasts.

"You just heard the blast. And everything started to be on fire. People came running out on fire," Walter Garduno said.

"People were alight - children," he added before trailing off.

From a few kilometers away, the multiple explosions that started at 2:50 pm (2050 GMT) almost looked festive, alight in blue, red and white. They were anything but.

Of the 31 confirmed dead, "26 (died) at the scene and five in hospitals," local media reported Mexico's chief prosecutor Milenio Alejandro Gomez as saying.

Forensic experts are working on genetic analyses of the bodies because "almost all of them are impossible" to identify, Mexico state's governor Eruviel Avila told the Televisa television network.

At least 72 were wounded, the authorities said. The injured were transported to emergency rooms, and 21 have since been released.

Fire crews struggled for three hours before bringing the blaze under control.Entire market blown up
The head of the civil protection service, Luis Felipe Puente, said crews had to wait for all the fireworks to finish exploding before they could extinguish the flames.

"The entire market is gone," he said. It had 300 stands.

Several of the injured were in "delicate condition," he added, saying searches were under way for more casualties in the scorched area that looked like a scene from a post-apocalyptic film, with little left standing in the smoldering ruins.

Homes and vehicles nearby were also severely damaged. In some areas, emergency workers were gently probing for survivors under heaps of charred and twisted roofing material.

People desperately searching for family and friends shouted and gestured to rescuers about where they hoped the missing might be found.

Most of those picked up by rescuers suffered severe burns, many over their entire bodies.

The military, which is in charge of issuing fireworks sales permits, was deployed to help emergency crews transport casualties to hospitals by ambulance and helicopter.