The epicentre was 11 kilometres (seven miles) southeast of Acapulco in Guerrero state, the National Seismological Service reported.
A man was killed when a utility pole fell on him in the nearby city of Coyuca de Benitez, Guerrero state governor Hector Astudillo told Milenio TV.
But President Andres Manuel Lopez Obrador said in a video message that there were no reports of significant destruction.
"The epicentre was registered in Acapulco, Guerrero. Fortunately, there is no damage in that state, no major damage," he said.
Utility poles and other debris fell on a number of vehicles in Acapulco and the facade of a church collapsed, according to an AFP correspondent.
Tourists evacuated hotels as dozens of aftershocks, including at least eight of magnitude 4 or above, rattled nerves.
"I was taking a bath and suddenly I felt a very strong movement and then I was scared and screamed," said a tourist from Mexico City who fled outside in only a bath towel.
"I came with my mom and we're on the 11th floor of the hotel," he said, hugging his 86-year-old mother, who was crying.
Acapulco Mayor Adela Roman said that the tremor sparked "nervous breakdowns" in the city.
"People are worried because there are aftershocks."
She said that "a lot of gas leaks" had been detected in residential areas.
Authorities in Acapulco opened sports centres for people to sleep in if they were afraid to go home.
A church in the city of Chilpancingo offered refuge to families evacuated from housing that suffered structural damage, the Guerrero civil defense service said.
The earthquake was felt strongly in parts of Mexico City, sending residents and tourists spilling into the streets from homes and hotels.
"I'm very scared. I don't know if I'll sleep tonight. I'm worried about my daughter. I woke her up to take her outside and I didn't even put my shoes on," said 49-year-old resident Laura Villa.
There were no immediate reports of serious damage in the capital, Mexico City Mayor Claudia Sheinbaum said on Twitter.
Several neighborhoods were left without power and the electricity board was working to restore it as soon as possible, she added.
Flashes of light were seen in the sky above the capital during the earthquake, which hit at a time when Mexico is facing a third wave of Covid-19 infections as well as severe flooding in some areas.
Bordered by the Atlantic and Pacific oceans, Mexico is one of the most seismically active places in the world, sitting atop five tectonic plates including three major ones.
On September 19, 1985, an 8.1 magnitude quake in Mexico City killed more than 10,000 people and destroyed hundreds of buildings.
On the anniversary of that earthquake in 2017, a 7.1 quake left around 370 people dead, mainly in the capital.