2009 was the year the tide turned in Phoenix. The real estate market in Maricopa County, which includes Phoenix, was in a firm state of collapse and unemployment had risen to 8.9 percent, from 5.1 percent the previous year. Just four years before, in 2005, Maricopa County led the country as a population magnet, taking in more taxpayers than any other county in the United States, according to IRS data.

In 2009, for the first time, more taxpayers left the county than moved in.

That was also a turnaround year for Allegheny County, Pa., home to Pittsburgh. The area struggled after the closure of large steel plants in the 1980s, and Pittsburgh’s population fell by more than half in the decades after 1950 — largely the result of people heading to the suburbs and to more robust economies in the West.

As recently as 2005, Allegheny County lost nearly 10,000 members of taxpaying households, according to IRS data. But in 2009, the losses turned to gain: more taxpayers moved to Allegheny County than moved out that year. (In 2010, the county slipped back to a modest net loss of 967 members of taxpaying households.)

“Pittsburgh’s third renaissance is happening,” says the city’s 32-year-old mayor, Luke Ravenstahl. Pittsburgh is one of several old-line cities that have rebounded during the recession. Assumed dead through dark years of suburbanization, industrial dismantlement and flight to the Sunbelt, many have turned to institutions founded during industrial heydays to successfully reconfigure their economies.

They were rewarded in the last decade when they avoided the real estate bubble and subsequent bust and found themselves with broad-based, fundamentally strong economies during the recession. Allegheny County’s unemployment rate stayed well below the national average.

In Pittsburgh, the renaissance Ravenstahl speaks of entailed partnerships with universities and philanthropies built on steel fortunes. Recognizing that the steel industry couldn’t support the city the way it had in the past, Pittsburgh’s leaders in the 1980s encouraged the emergence of a new economy built around Carnegie Mellon University and the University of Pittsburgh as well as the city’s hospitals. The effort found 21st-century vindication when tech titan Google opened an office in the city last year, and Pittsburgh will soon boast the world’s largest “living” green building at the Phipps Conservatory.

The city has worked to retain families who might otherwise move to the suburbs. Ravenstahl’s spokeswoman, Joanna Doven, points to the Pittsburgh Promise, a private effort backed by the University of Pittsburgh Medical Center that gives a $40,000 college scholarship to every public school student with a grade-point average of at least 2.5 and a good attendance record.

During the recession, Pittsburgh’s economy was helped in part by the fact that the area’s housing market remained relatively flat while others bubbled, and foreclosure rates were consequently lower during the recession.

The Internal Revenue Service tracks migration through tax returns: when a taxpayer, identified by a Social Security number or taxpayer identification number, files from a new address, the IRS assumes he’s moved in the last year. The resulting migration database comes at an astonishing level of detail — for any county in the country, it lists characteristics of people who moved to any other county, removing some records to maintain privacy — but only accounts for people who are taken as an exemption on an income tax return. That means the data don’t include households that don’t pay income taxes, including some retirees and unemployed people.

Even as more people have moved to such places as Milwaukee, Minneapolis and Washington, D.C., migration overall has fallen over the last five years — a continuation of a trend that dates back at least 25 years, according to research by demographer William Frey, a senior fellow at the Brookings Institution.

The IRS found that 13.4 million people moved between counties in the year ending April 2005, and just 12.6 million in the year ending April 2010. Frey links some of the positive demographic trends in these cities to what he calls windfall stayers — people “who otherwise would have moved out either to their own suburbs, or to more economically vibrant places,” he says. They’re joined by people Frey calls return migrants, those “whose jobs were eliminated [elsewhere] or whose homes were foreclosed upon.” Frey adds, “when times are tough, people rely on familiar communities and family, and return to join them.”

To find these comeback cities, we screened the IRS’s database to look for counties that were losing population in 2005 but that were either gaining in 2010 or losing far fewer people. Every city on this list saw more people move in in 2010 than in 2005, so we aren’t merely recognizing cities that have already lost all of their mobile population.