Officials did not rule out the possibility the death toll could rise more as emergency workers continued sifting through the charred remains of vehicles and homes built near the highway on the northern edge of the metropolis.
Residents pitched in to rescue people from the wreckage of crushed and burned cars and shattered homes. Television footage showed plumes of flame shooting out of homes in the pre-dawn darkness.
Authorities did not immediately report a cause for the explosion.
"We just pulled burned people, and put out the fire in the houses, but we don't really know what happened," said Rogelio Martinez, a resident of the neighborhood where the crash occurred.
Emergency personnel at the scene pulled dead victims from their homes, some apparently burned in their beds. An Associated Press journalist at the scene saw rescue workers take three bodies, covered with white sheets, from one home.
A huge piece of the truck's gas tank was blown 50 yards by the force of the blast, landing atop the wall of a house and cars parked outside. Charred wreckage of cars littered the blast site.
One small passenger van had been totally gutted by flames and tossed against the wall of one of the many improvised houses built next to the highway.
Hundreds of police, ambulance drivers, paramedics, soldiers and firefighters gathered at the scene, where a giant plume of smoke rose over the area after the explosion around 5 a.m. Tuesday local time.
Pablo Bedolla, the mayor of Ecatepec, a mainly working-class area, said 20 homes and one school had been damaged in the blast. The explosion happened before class hours, so there were no apparent injuries in the school.
"People are very shaken, above all because of the injuries and the large number of dead," said Bedolla. "I've spoken with the families of the victims, and they are just sobbing."
The explosion closed the highway between Mexico City and Pachuca for hours.
The pre-dawn accident exposed two recurrent public safety issues in Mexico: extremely heavy trucks that are frequently involved in serious accidents, and the construction of improvised homes just feet away from major highways.
Some of the cinderblock homes hit by the massive explosion were just steps away from the busy, four-lane highway. Other homes were mere shacks, built of sheet tin.
Mexican trucks, often overloaded or unsafely operated, have been involved in a number of spectacular, deadly accidents in recent years.
The truck involved in Tuesday's accident was a double tanker: one cab pulling two gas tanks. The driver was injured in the crash, and was under detention at a local hospital.
One year ago, the Mexican government announced measures to tighten inspections and lower maximum allowed weights for freight trucks after protests over a string of deadly accidents involving double-trailer trucks.
Mexico had allowed trucks to travel two-lane roads with loads of up to 80 metric tons and lengths exceeding 100 feet, compared to a U.S. limit of is 80,000 pounds (40 tons) on interstate highways. It subsequently reduced that limit by about 4.5 tons.
In April 2012, a double-trailer truck on a two-lane road in the Gulf coast state of Veracruz lost its rear trailer, which slammed into a bus carrying farm workers, killing 43 people.