More than 70 others were injured as the blast hit the San Pablito fireworks market in Tultepec, about 20 miles (32km) outside the city.
Video from the scene showed a large number of fireworks rocketing into the air as they caught fire.
Dozens of paramedics and police attended the scene. The cause of the explosions is not yet known.
Locals have been told to avoid the area and keep roads clear.
Eruviel Avila, governor of the State of Mexico, said some children had suffered burns to more than 90% of their bodies and they were being sent to the US city of Galveston, Texas, for specialised treatment.
Most of those killed are so badly burned their bodies will have to be identified using DNA testing, he added.
Fireworks continued to explode after the initial blast, as smoke billowed from the area in thick black clouds. The market had contained up to 300 tonnes of fireworks, Mexican media reported.
Photos from police and medical personnel at the scene showed several injured people among the destroyed market stalls, with brick buildings scorched by the heat.
"The sound of blasts started to go off and we thought it was a nearby fireworks workshop," local resident Alejandra Pretel told the AFP news agency.
However, she said it soon became clear the entire market was at risk.
"My neighbours said they felt everything shake, but I didn't realise because I was running away," she said.
Angelica Coss, 25, said the explosions sounded "like a plane had crashed, like bombs were being dropped".
"I went up to the roof of my place and others were already there and we saw the market was blowing up. And all the smoke started to cover us," she said.
The president of Mexico, Enrique Pena Nieto, tweeted condolences to the families of the victims and wished a speedy recovery to the injured.
He also said members of the defence forces were assisting in the emergency.
The San Pablito market was heavily damaged by similar fires in September 2005, when a chain of explosions just before the country's independence day celebrations injured dozens of people.