The U.S. Geological Survey said the quake occurred at 6:47 p.m. local time just north of the fishing and resort town of Puerto Angel.
Residents there described the quake as more noise than shaking, and no damage or injuries were reported.
The shaking did set off earthquake evacuation alarms in the state capital of Oaxaca, 65 miles northwest of the epicenter.
People streamed out of shops, homes and offices due to the alarm, which is designed to go off when a quake registers a magnitude greater than 5.0.
One Twitter user in Mexico City said his building shook for approximately 30 seconds.