But what spared this metropolitan area of 21 million was, at least in part, luck.
The 1985 earthquake was 30 times more powerful than the one on Tuesday. It toppled apartment and office towers, killing more than 10,000 people.
Tuesday’s earthquake, while centered closer to the capital, struck hardest at smaller, less populated buildings, taking fewer lives.
“They were different seismic activities, in magnitude but especially given the distance,” said Dr. Eduardo Reinoso, a researcher specializing in seismic engineering at the National Autonomous University of Mexico. “Because this one was much closer, the shock waves were different. This quake affected shorter houses and buildings, while in 1985 the collapses were mostly high-rises because of the different waves.”
In a 2016 study of a random sample of 150 buildings constructed after 2004, when the new codes were adopted, Mr. Reinoso found that many failed to meet city standards. In many cases, the buildings reviewed did not even have enough necessary paperwork to conduct a full assessment.
As it often goes in Mexico, it is not the law that is problematic, but rather the implementation. Whether because of a lack of political will, the corruption that seethes through the system or the dysfunction of the bureaucracy, one of the deadliest threats that the nation faces has been left unfixed. Once the dust settles, officials will be confronted once more with a choice: whether to truly enforce a public safety imperative or continue with reforms that seem to exist mostly on paper.
“Some developers have their preferred inspectors and they usually hire the same person for their buildings, so that inspector is active, familiar, and always has a ton of work,” said Jorge Ortiz, an engineer and architect who is one of several hundred contract inspectors for the city. “And sometimes if you have several projects, they aren’t there as much or are not present at all phases of construction and that’s when there’s carelessness.”
According to last year’s study, of the buildings that could be fully inspected, 71 percent failed to meet a high threshold of compliance with the city standards, while 36 percent failed to meet even a lower threshold of compliance.
“It would appear that the regulator is not performing its duty,” the study concluded.
But the inspection of older buildings can also be lax, which might have been the case in the tragedy at the Enrique Rebsamen School , where 19 children and 6 adults died this past week following the collapse of one of its buildings.
City code requires that certain buildings, including schools, be inspected for safety after an earthquake. After a massive earthquake hit Mexico on Sept. 7, an inspector was dispatched to the school.
The contracted inspector signed off on the structure, deeming it safe, said Claudia Sheinbaum, the local delegate in charge of the district where the school is located.
“They came to the school to verify the building and said it was O.K.,” she said.
There are still tens of thousands of pending requests across the city for engineers to review structural damages, so the estimate of damaged buildings is likely to grow.
As in many of the recovery efforts, legions of volunteers have raised their hands to help in the building assessments. A patchwork group of engineering groups and nongovernmental organizations have taken to the streets to assess the status of structures whose sagging frames pose dangers to neighboring buildings as well as passers-by.
Still, it could have been worse, a message that some in the civil engineering community are hoping to send to Mexico City officials to prompt changes to the conflict-ridden system of building inspections.
“We are concerned if we have a huge earthquake like the one in 1985 we may have problems in buildings,” said Sergio Alcocer the vice president of the Mexican Society of Civil Engineers and the former head of structural engineering for the government’s Center for the Prevention of Natural Disasters. “It’s a wake-up call.”
Mr. Alcocer said that while the system was imperfect, he was pleased with how some larger structures held up under Tuesday’s seismic shudders. But he feared that builders, who often hire the cheapest inspectors to review their buildings and may not follow code, might take the wrong lesson from the earthquake if their buildings did not fall.
“In another type of earthquake, we could have problems in buildings that fared well this time,” he said.
(Yet another earthquake, this one of 6.1 magnitude and centered in the state of Oaxaca, shook Mexico City just before 8 a.m. Saturday, and anxious residents, some in pajamas, raced into the streets. In the Oaxaca city of Juchitán, several houses damaged in the 8.1 earthquake three weeks ago, collapsed, and so did a bridge.)
No two earthquakes are the same, even two that strike in the same seismic region. The 1985 quake and the one on Tuesday occurred in the same subduction zone, an area where one of the earth’s large crustal plates is sliding under another.
The 1985 quake, at magnitude 8.1, released about 30 times more energy than Tuesday’s magnitude 7.1 quake. But it also struck twice as far from the capital – 220 miles compared with about 100.
There were other differences as well: the 1985 quake was shallower, and even the orientation of the faults — the direction the rocks moved in — was different.
All of those factors affected the toll in destroyed buildings — about 350 in 1985 and one-tenth that number on Tuesday — and in deaths. Four days after Tuesday’s quake, the death toll was still climbing, but the final tally will be nowhere near the estimated 10,000 who died in 1985.
Generally, a more powerful quake would cause more shaking and greater destruction. Being farther away would tend to reduce the impact.
But in the case of the 1985 earthquake, the larger distance from the epicenter played a critical role in which buildings were damaged and destroyed, and in the death toll as well.
After that quake, engineers noticed a pattern to the destruction. Of the hundreds of buildings that collapsed or were heavily damaged, most were six to 16 stories tall.
The reason soon became apparent. High-frequency waves of energy generated by the quake dissipated over the miles to Mexico City, leaving mostly low-frequency waves to reach the capital. It’s similar to how, when listening to far-off music, treble sounds tend to be absorbed and only bass sounds reach the ear.
During the earthquake, those lower-frequency waves rolled through the city about one second apart. That closely matches the natural resonance, or rate of vibration, of buildings about 60 to 160 feet tall.
Successive waves caused those buildings to sway more and more. The soft sediments that the city is built on, which tend to amplify movements, made the swaying even worse until the structures failed.
In the quake on Tuesday, however, “there wasn’t as much distance for that higher frequency energy to be absorbed,” said Gavin Hayes, a geophysicist with the United States Geological Survey. As more of these shorter, faster waves reached the city, smaller buildings vibrated until failure. Taller buildings were generally spared this time.
Since smaller buildings hold fewer people, that helped keep the death toll down.
But not all larger buildings were spared. In an area called Portales Sur, which sits on the fringe of the rapidly gentrifying neighborhood of Narvarte, buildings have sprung up in recent years for young professionals looking to own their first home in the city.
The builder of a six-story condominium completed this year promised the latest in technology and design – apartments constructed of concrete and steel-draped elegance. Rainwater cisterns fed eco-friendly plumbing, while solar panels stationed by the rooftop garden powered units that sold for about $150,000.
The building collapsed on Tuesday, taking with it the lives of two people. Now, its remains sit in a pile of twisted metal and fractured concrete, testament to the often-shoddy construction and lax inspections that helped clear the way for a voracious real estate boom in the capital, according to experts and officials.
Residents are searching for legal recourse, given the failure of inspectors to detect or report the structural flaws.
They have to. Many did not have property insurance, as few people do in Mexico, and the developer has claimed the quake was unforeseeable, raising fears among the unit owners that the company may try to abdicate responsibility.
“I can’t believe something like this can happen in a new building,” said Luis Reséndiz, 35, a photographer who said he saved for five years to buy an apartment there. “This is the fruit of many years of labor, and here it is, all lost.”