An earthquake of magnitude 8.1 struck off the southern coast of Mexico late on Thursday, the US Geological Survey (USGS) said, killing more than 20 people and shaking buildings as far away as Guatemala as people ran into the streets of Mexico City.
The quake at 11.49pm local time triggered waves as high as 2.3 ft (0.7 m) in Mexico, the Pacific Tsunami Warning Center (PTWC) says. It says widespread hazardous tsunami waves were possible within three hours.
A number of buildings suffered severe damage in parts of southern Mexico. Some of the worst initial reports came from Juchitan in Oaxaca state, where sections of the town hall, a hotel, a bar and other buildings were reduced to rubble.
The cornice of a hotel collapsed in the southern tourist city of Oaxaca, a witness reports.
The governor of Oaxaca, Gabino Cué Monteagudo, told Reuters that 20 people were killed in his state as a result of the earthquake.
Four people were killed in his state, says Manuel Velasquez, the governor of Chiapas.
Two children were killed in neighbouring Tabasco state, the state governor said.
Mexico's civil protection agency says it was the strongest earthquake to hit the country since a devastating 1985 tremor that toppled buildings and killed thousands.
The organisation's national coordinator said on Twitter that low-lying zones in the states of Oaxaca and Chiapas could expect waves of up to 4.2 metres.
People in the capital, one of the world's largest cities, ran out into the streets in pyjamas as alarms sounded after the quake struck just before midnight, a Reuters witness said.
Helicopters hovered overhead a few minutes later, apparently looking for damage to buildings in the city built on a spongy, drained lake bed.
In one central neighbourhood, dozens of people stood outside after the quake, some wrapped in blankets against the cool night air as children were crying.
Liliana Villa, 35, was in her apartment when the earthquake struck and she fled to the street in her pyjamas.
"It felt horrible, and I thought, 'this is going to fall'."
"I had never been anywhere where the earth moved so much. At first I laughed, but when the lights went out I didn't know what to do. I nearly fell over," says Luis Carlos Briceno, an architect, 31, who was visiting Mexico City.
The quake struck at a depth of 33 kilometers (21 miles) offshore in the Pacific about 120 kilometres southwest of the town of Tres Picos in far southern Chiapas state, the US Geological Survey (USGS) says.
USGS reported several aftershocks, all greater than 5 magnitude.
"Based on all available date ... widespread hazardous tsunami waves are forecast for some coasts," the Pacific Tsunami Warning Center says.
"Tsunami waves reaching more than three meters above the tide level are possible along the coasts of Mexico," it states, with lower waves in other countries.
The tsunami warning was for the coasts of Mexico, down through Central America into Guatemala, El Salvador, Costa Rica, Nicaragua, Panama and Honduras, and as far south as Ecuador.
The quake was also felt in much of Guatemala, which borders Chiapas.
State oil company Pemex said it was still checking for damage at its installations, which include the Salina Cruz refinery in the same region as the epicentre.