There were no immediate reports of damage or injuries.
The US Geological Survey said the quake took place at 5:46 am (1046 GMT) in Veracruz state, at a depth of 95 kilometres and 19 kilometres southwest of the municipality of Juan Rodriguez Clara.
National civil protection coordinator Luis Felipe Puente said no casualties or damage were spotted after authorities checked the entire state of Veracruz.
Some hotels were evacuated in the neighboring state of Oaxaca.
The quake took place 418 kilometres southeast of Mexico City, rattling buildings and prompting residents to evacuate their homes.
More From This Section
Rosalinda Gonzalez, a 38-year-old secretary, fled from her apartment in her pajamas in downtown Mexico City.
"My (baby) daughter began to cry and when I got up I saw that it was shaking because her crib's mobile was moving by itself," she said.
Mexico is one of the most seismically active places in the world.
Mexico City is sensitive to distant earthquakes because it was built over soft soil from a drained lake that magnifies their effect.
In 1985, thousands of people were killed in the capital when buildings collapsed after an 8.1-magnitude temblor struck the Pacific coast.