Living in cities, although stressful and unhealthy now, seem to have helped people long ago to protect their descendants from disease.
Some people carry a genetic sequence, or allele, that provides immunity to leprosy and tuberculosis.
Mark Thomas of the University College London, and Ian Barnes of the University of London, wondered whether this genetic immunity could have been gained when people began living in close proximity, reports New Scientist.
Poor sanitation would have meant that disease was rife in ancient cities, but exposure to the pathogens would have led to resistance developing, which the inhabitants would have passed onto their descendants.
To test this idea, Thomas and colleagues analysed the DNA of people living in 12 regions in Europe, Asia and Africa.
For each area, they combed the historical and anthropological records to work out when people first started living in close-knit groups. They found that the longer cities in the region had been established, the more likely it was that the current inhabitants carried the immunity allele.
It had been thought that the allele became prevalent when cattle were first domesticated, as cows carry a strain of TB that humans can catch.
But the team found a stronger correlation between the allele and urbanisation than with the onset of cattle farming.
It is likely that cattle domestication would have played a role in developing the immunity, because cattle farming would have been important in early city life, Barnes points out.
Thomas described population dynamics as "an awesome, underplayed feature of our history" and thinks resistance to other diseases could also have evolved in this way.