A gas tanker has exploded on a highway in the Mexico City suburb of Ecatepec, killing at least 21 people and injuring nearly three dozen, according to the Citizen Safety Department of Mexico State, which surrounds Mexico City.

The blast rocked a neighbourhood of Ecatepec, north of the Mexican capital, in the early hours of the day, injuring at least 36 people while affecting 15 cars and 27 homes, the mayor and a Mexico state official said.

Nearby buildings, cars and lorries burst into flames when the tanker exploded before sunrise in the community of San Pedro Xalostoc, which is part of the municipality of Ecatepec and is home to a 16th century church.

Officials did not rule out the possibility that the death toll could rise as emergency workers continued sifting through the charred remains of vehicles and homes built near the highway on the northern edge of the metropolis.

The explosion closed the highway between Mexico City and Pachuca.

A huge piece of the lorry's gas tank was blown a hundred metres 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.

Hundreds of police, ambulances drivers and paramedics, soldiers and firefighters gathered at the scene, where a giant plume of smoke rose over the area after the explosion around 5am Tuesday local time.

The pre-dawn accident exposed two recurrent public safety issues in Mexico: extremely heavy lorries 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, six-lane highway.

Mexican lorries, often overloaded or unsafely operated, have been involved in a number of spectacular, deadly accidents in recent years.

One year ago, the Mexican government announced measures to tighten inspections and lower maximum allowed weights for freight lorries after protests over a string of deadly accidents involving double-trailer lorries.

Mexico had allowed lorries to travel two-lane roads with loads of up to 80 metric tonnes and lengths exceeding 100ft, compared to a US limit of is 40 tonnes on interstate highways.

It subsequently reduced that limit by about 4.5 tonnes.

In April 2012, a double-trailer lorry on a two-lane road in the Gulf coast state of Veracruz lost its rear trailer, which crashed into a bus carrying farm workers, killing 43 people.