Mexico City was once known for its smoggy landscape with industrial eyesores such as the 18 de Marzo Refinery spewing ozone-forming emissions such as sulfur dioxide. The cloud of contaminants hanging over the capital played into an apocalyptic reputation for pollution, crime, and overpopulation; and it fueled urban myths, like the one about birds dropping dead mid-flight because of the poor air quality.

But the refinery – named for the day Mexico expropriated its oil industry – was ordered closed in 1991, and converted into a park commemorating the country's 2010 bicentennial. It is but one example of industry exiting Mexico City and the steps taken to improve air quality over the past two decades in this megalopolis of more than 20 million people.

With urbanization advancing, economies expanding, and climate change a concern, Mexico City has emerged as an unlikely environmental example for cities in developing countries suffering similar air quality issues.

Mexico City recorded only eight days with air quality considered "good" in 1992. That compares with 248 "good" air days in 2012, reflecting the success of initiatives to relocate industry, kick clunkers off the capital's streets, encourage cleaner technologies, and expand public transit and cycling options.

"Mexico City is still perceived as one of the most contaminated [cities] in the world, but nowadays there are cities ... that have worse contamination," says Roberto Muñoz, a biologist teaching at the Ibero-American University.

Closing the refinery was among the first actions in cleaning up the capital as industries either invested in new technologies, ceased operations, or moved to other states.

The state oil company Pemex started selling lower-sulfur and unleaded gasoline, while a program known as "Hoy no Circula," or "No driving today," forced motorists off the road one day a week. Vehicles also had to undergo emissions tests.

Slowly but surely air quality improved here in spite of obstacles such as unfavorable geography, which keeps contamination in the Valle de México – the high-altitude valley containing Mexico City and the surrounding state of Mexico.

Left-wing administrations led by Mayors Andrés Manuel López Obrador and Marcelo Ebrard between 2000 and 2012 in the Federal District – home to about 9 million residents; another 11 million live in municipalities in the state of Mexico – took policies that targeted pollution even further.

The Mexico City government opened dedicated lanes for a public transport system known as Metrobus, built a new subway line, and launched a bicycle-sharing service, which was expanded after waits for new memberships reached six weeks. Mexico City is home to more than 4 million vehicles, and still faces notorious traffic problems, but this year it received the Institute for Transportation & Development Policy's Sustainable Transport Award.

Levels of ozone have dropped drastically, Mr. Muñoz says, although the levels of particulate matter pollution – tiny particles that can cause heart and lung problems – remain a concern.

"The problem with contamination is [it's mostly] coming from vehicular sources" in Mexico City, Muñoz says.

Cars are big contributors to air pollution in other parts of the country as well, where poor public policy is contributing to deteriorating air quality, says Gabriela Alarcón, director of urban development studies at the think tank Mexican Institute for Competitiveness.

A glut of imported vehicles – many illegal and older models – have entered the country over the past 10 years and the federal government has spent more than $50 billion on gasoline and diesel subsidies since 2008, which has encouraged more private vehicle use across Mexico, Ms. Alarcón says.

Get the Monitor Stories you care about delivered to your inbox. By signing up, you agree to our Privacy Policy

Government housing programs over that same time frame gave rise to far-off exurbs, creating lengthy commutes, adds Guillermo Velasco Rodríguez, director of planning and projects for the Centro Mario Molina. Mr. Rodríquez acknowledges the improvement in air pollution in Mexico City but cautions against prematurely celebrating.

"It sounds good if you compare it to 1992," he says, "but it's not [yet] what we want."