There were no immediate reports of damage or injuries.
The quake hit at 7:04 a.m. (9:04 a.m ET), about 11 miles west-southwest of the city.
It happened at a relatively shallow depth of 4.7 miles, USGS said.
A second quake, registering a magnitude of 5.1, struck nearby a few minutes later, USGS reported.
The governor of Oaxaca, Gabino Cue, said a post-earthquake alert was activated, but said there were no injuries.
“As of now, we have no reports of damage,” he added.