Mexico's president said the quake was an aftershock and was also felt in the states of Colima, Jalisco and Guerrero.
Claudia Sheinbaum, the mayor of Mexico City, said that two people died - a woman who fell down the stairs of her house and a man who had a heart attack.
Residents thronged the streets as the seismic alarm went off.
An earthquake rocked an already restless country.
The stronger quake was the third major earthquake to hit.
The quake occurred shortly after the annual earthquake anniversary of the devastating 1985 earthquake that claimed lives.
About 9,500 people.