A man sits in his wheelchair backdropped by a building damaged in a massive earthquake, in Juchitan, Oaxaca state, Mexico Friday, Sept. 8, 2017. One of the most powerful earthquakes ever to strike Mexico has hit off its southern Pacific coast, killing at least 32 people, toppling houses, government offices and businesses. (AP Photo/Luis Alberto Cruz)
A man sits in his wheelchair backdropped by a building damaged in a massive earthquake, in Juchitan, Oaxaca state, Mexico Friday, Sept. 8, 2017. One of the most powerful earthquakes ever to strike Mexico has hit off its southern Pacific coast, killing at least 32 people, toppling houses, government offices and businesses. (AP Photo/Luis Alberto Cruz) Credit: Luis Alberto Cruz

MEXICO CITY — One of the most powerful earthquakes ever recorded in Mexico struck off the country’s southern coast, toppling hundreds of buildings and sending panicked people fleeing into the streets in the middle of the night. At least 61 people were reported dead.

The quake that hit minutes before midnight Thursday was strong enough to cause buildings to sway violently in the capital city more than 650 miles away. As beds banged against walls, people still wearing pajamas ran out of their homes and gathered in frightened groups.

Rodrigo Soberanes, who lives near San Cristobal de las Casas in Chiapas, the state nearest the epicenter, said his house “moved like chewing gum.”

The furious shaking created a second national emergency for Mexican agencies already bracing for Hurricane Katia on the other side of the country. The system was expected to strike the Gulf coast in the state of Veracruz late Friday or early today as a Category 2 storm that could bring life-threatening floods.

President Enrique Pena Nieto said Friday evening in a televised address that 61 people were killed — 45 in Oaxaca state, 12 in Chiapas and 4 in Tabasco — and he declared three days of national mourning.

The worst-hit city was Juchitan, on the narrow waist of Oaxaca known as the Isthmus, where 36 quake victims died.

About half of Juchitan’s city hall collapsed in a pile of rubble and streets were littered with the debris of ruined houses. A hospital also collapsed, Pena Nieto said after touring the city and meeting with residents. The patients were relocated to other facilities.

The president said authorities were working to re-establish the supply of water and food and provide medical attention to those who need it. He vowed the government would help people rebuild and called for people to come together.

“The power of this earthquake was devastating, but we are certain that the power of unity, the power of solidarity and the power of shared responsibility will be greater,” Pena Nieto said.

Mexico City escaped major damage, but the quake terrified sleeping residents, many of whom still remember the catastrophic 1985 earthquake that killed thousands and devastated large parts of the city.

Families were jerked awake by the grating howl of the capital’s seismic alarm. Some shouted as they dashed out of rocking apartment buildings. Even the iconic Angel of Independence Monument swayed as the quake’s waves rolled through the city’s soft soil.

Elsewhere, the extent of destruction was still emerging. Hundreds of buildings collapsed or were damaged, power was cut at least briefly to more than 1.8 million people and authorities closed schools Friday in at least 11 states to check them for safety.

The Interior Department reported that 428 homes were destroyed and 1,700 were damaged in various cities and towns in Chiapas.

The earthquake’s impact was blunted somewhat by the fact that it was centered 100 miles offshore. It hit off Chiapas’ Pacific coast, near the Guatemalan border, with a magnitude of 8.1 — equal to Mexico’s strongest quake of the past century. It was slightly stronger than the 1985 quake, the U.S. Geological Survey said.

The epicenter was in a seismic hotspot in the Pacific where one tectonic plate dives under another. These subduction zones are responsible for producing some of the biggest quakes in history, including the 2011 Fukushima disaster and the 2004 Sumatra quake that spawned a deadly tsunami.

Dozens of strong aftershocks rattled the region in the following hours.

“There is damage to hospitals that have lost energy,” he said. “Homes, schools and hospitals have been damaged.”