The U.S. Geological Survey said the quake struck at 11:49 p.m. Thursday local time and its epicenter was 102 miles west of Tapachula in southern Chiapas state not far from Guatemala. It had a depth of 22 miles.
Mexico's president said the quake is the country's strongest in a century.
Oaxaca state Gov. Alejandro Murat told local news media that at least 23 people in his state died.
Civil defense officials say at least seven people died in the state of Chiapas, which borders Guatemala. Two others died in the Gulf coast state of Tabasco.
The U.S. Tsunami Warning System said hazardous tsunami waves were possible on the Pacific coasts of several Central American countries, including Guatemala, El Salvador, Costa Rica, Nicaragua, Panama, and Honduras, within three hours. There was no tsunami threat for the U.S. West Coast, but the warning system said waves could reach Mexico and as far as Ecuador.
The U.S. Tsunami Warning System said tsunami waves were beginning to be observed along the coast of Mexico, initially, the highest was less than 3 feet.
Several powerful aftershocks also appeared to hit the area.
Seismologist Lucy Jones with Caltech said a tsunami would not reach as far as California or Hawaii.
"The good news is that it's offshore and therefore, everybody's a certain distance away from it," Jones told Eyewitness News. "The bad news is being offshore, it can change the shape of the sea floor and that's what can generate a tsunami."
Civil Defense in Chiapas said on its Twitter account that its personnel were in the streets aiding people and warned residents to prepare for aftershocks. But it made no immediate comment about damage.
"The house moved like chewing gum and the light and internet went out momentarily," said Rodrigo Soberanes, who lives near San Cristobal de las Casas in Chiapas, a poor largely indigenous state popular with tourists.
The quake was so powerful that frightened residents in Mexico City more than 650 miles away fled apartment buildings, often in their pajamas, and gathered in groups in the street.
Buildings swayed strongly for more than one minute, loosening light fixtures from ceilings. Helicopters crisscrossed the sky above Mexico City with spotlights. Some neighborhoods kept electricity while others remained in darkness.
The governor of Oaxaca, Mexico, reported that a hotel in the area suffered structural damage. The state coordinator of civil protection tweeted out a photo of the damaged building.
In neighboring Guatemala, President Jimmy Morales spoke on national television to call for calm while emergency crews checked for damage. Local radio in the Central American country reported one death, but it could not be confirmed.
"We have reports of some damage and the death of one person, even though we still don't have exact details," Morales said. He said the possible death occurred in San Marcos state near the border with Mexico.
The Associated Press and ABC News contributed to this report. null