The tremor on Tuesday struck eight kilometres southeast of Atencingo in the central state of Puebla, some 120km from the capital, Mexico City, the US Geological Survey (USGS) said.
Scores of buildings collapsed into mounds of rubble or were severely damaged in densely populated parts of Mexico City and nearby states.
“A total of 138 people have sadly lost their lives,” the director of the government’s civil protection service, Luis Felipe Puente, told the Televisa television network.
He said there were 36 deaths in Mexico City and the rest in regions just to the south and the west of it.
Morelos state, directly south of the capital, suffered 64 deaths.
The state of Puebla, where the epicentre of the earthquake struck, reported at least 29 deaths. And nine people died in Mexico state, which lies just to the west of Mexico City.
The capital’s international airport suspended operations and was checking facilities for any damage.
Clouds of dust rose from fallen pieces of facades in Mexico City, and local TV footage and social media purportedly showed some buildings with severe damage.
Rescue workers and residents dug through the rubble of collapsed buildings seeking survivors.
At one site in the Mexico City neighbourhood of Roma, rescue workers cheered as they brought a woman alive from what remained of a toppled building.
Local media broadcast video of whitecap waves churning the city’s normally placid canals of Xochimilco as boats bobbled up and down.
Al Jazeera journalist Ali Rae, who was in Mexico City when the earthquake struck, said: “The building I was in began to sway back and forth. As the waves got stronger, the shelves began to empty and a glass cabinet fell nearby.
“My friend and I were in a bit of shock. My legs felt like jelly as we left the building to join others outside. While it was a bit of a scare for us – we were completely fine compared to other parts of the city hit a lot worse.”
Al Jazeera’s Ampraro Rodiguez, reporting from Mexico City, said that while this wasn’t the strongest earthquake Mexico has experienced in the last month, “what makes it different is that the epicentre was quite close to the capital”.
Hours after the quake, rescue workers were still clawing through the wreckage of a primary school that partly collapsed in Mexico City, looking for any children who might be trapped. Some relatives said they had received Whatsapp messages from two girls inside.
Earlier this month, a powerful 8.1 quake hit southern Mexico, killing at least 98 people.
The worst earthquake in the history of Mexico occurred on September 19, 1985, killing nearly 10,000 people.
Mexico City was among the places that were seriously affected.