Ed Glaeser, an economics professor at Harvard University and the author of “Triumph of the City,” said watching the virus rip through cities was like going back in time. “It feels like it’s back to smallpox, it’s back to cholera,” he said.

“Cities were killing fields for centuries because of contagious disease,” he said, noting that the life expectancy of a baby born in a city in 1900 was seven years less than one born in a rural area. That gap disappeared by the 1920s, with the advent of modern water and sewer systems.

Over time, density became a boon, economically, socially, intellectually. Living in a city became a way to encourage health. People could walk where they needed to go and support one another in tight-knit social networks.

As the threat of the coronavirus lessens, some who fled major cities might elect to stay away while others will want to flock back to the perks of urban living.

“How people behave in a pandemic is probably not a great guide to how they want to live their lives in normal times,” Mr. Kolko said. “We are living in the middle of a grand forced experiment, but we really don’t know how the experiment is going to play out.”