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.
Authorities in Chiapas said at least three people were killed, while officials in Tabasco state reported the two children killed.
Tabasco Gov. Arturo Nunez said that one of the children died when a wall collapsed, and the other was a baby who died in a children's hospital that lost electricity, cutting off the supply to the infant's ventilator.
In Chiapas, Gov. Manuel Velasco told Milenio TV that the deaths occurred in San Cristobal de las Casas. He also said that the quake damaged hospitals and schools.
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.