The US Geological Survey said the quake in the Pacific Coast state of Guerrero had a preliminary magnitude of 5.4.
The southern state's government said it had initiated security protocols but did not immediately report damage or injuries.
Many office workers evacuated their buildings after the quake set off alarms in Mexico City but Mayor Miguel Angel Mancera said in a message from his Twitter account that there were no immediate reports of damage or injuries.
Mexico City is vulnerable to distant earthquakes because much of it sits atop the muddy sediments of drained lake beds. They jiggle like jelly when quake waves hit.