State security officials counted 33 people with various injuries.
The driver, who was under detention while being treated at a hospital, could face manslaughter and property damage charges, the prosecutor said.
"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.
Emergency personnel at the scene pulled dead from their homes, some apparently burned in their beds. An Associated Press journalist saw rescue workers carry three bodies, covered with white sheets, from one home.
One small passenger van had been totally gutted by flames and tossed against the wall of one of the many improvised houses next to the highway.
Hundreds of police, ambulance drivers, paramedics, soldiers and firefighters gathered at the scene.
Pablo Bedolla, the mayor of Ecatepec, a mainly working-class area, said 20 homes and one school had been damaged by 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," Bedolla said. "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.
Speaking in Mexico City, President Enrique Pena Nieto suggested something would have to be done to separate major highways from poor neighborhoods.
"I have instructed the Transportation Department ... to review the safety conditions on this federal highway in places where structures have been built on the right of way, so that in the near future, work can be carried out to make it safer," Pena Nieto said.
Often in Mexico, squatters settle on rights of way, the strips of land on either side of a highway or railway line that are intended to be buffer zones. The gradual spread of shacks creates neighborhoods that are inherently unsafe.
This highway, however, was recently expanded, so it was unclear whether the land occupied by homes was legally settled.
The Mexican government also appears to have realized it has a big problem with over-weight trucks. Such trucks, often unsafely operated, have been involved in a number of spectacular, deadly accidents in recent years.
On Tuesday, the Transportation Department announced it had set up a panel of experts to study the issue of maximum allowable weights, "to set out opinions on eventually changing the weight standards, or drawing up a new set of rules."
One year ago, the Mexican government announced measures to tighten inspections and lower maximum allowed weights for some freight trucks after protests over a string of deadly accidents involving double-trailer trucks like the one involved in Tuesday' disaster.
Mexico has allowed trucks to travel highways with loads of up to 80 metric tons and lengths exceeding 100 feet, compared to a U.S. limit of 80,000 pounds, or 40 tons, on interstate highways.
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.
Associated Press writers Mark Stevenson and Gloria Perez contributed to this report.
AP video: http://www.youtube.com/watch?v=jXv190oaFVw