Luis Felipe Puente, head of the Mexican government's emergency services, said on Twitter there were no immediate reports of damage and the US Pacific Warning Center said it did not expect the quake to trigger a destructive tsunami.
Nevertheless, residents of the capital were shaken by the quake, one of the biggest to hit Mexico in several years.
"I had to hold on to a tree, like a drunk," said Pedro Hernandez, 68, a doorman working in central Mexico City.
The USGS said the quake was centered some 37 km (23 miles) north of the municipality of Tecpan de Galeana in Guerrero. It was relatively shallow, at a depth of 30.2 miles (49 km).