Active celiac disease can cause severe health problems, from stunting and osteoporosis to miscarriage. It strikes a relatively small number of people — just around 1 percent of the population. Yet given the significant costs to fitness, you’d anticipate that the genes associated with celiac would be gradually removed from the gene pool of those eating wheat.

A few years ago, Dr. Jabri and the population geneticist Luis B. Barreiro tested that assumption and discovered precisely the opposite. Not only were celiac-associated genes abundant in the Middle Eastern populations whose ancestors first domesticated wheat; some celiac-linked variants showed evidence of having spread in recent millenniums.

People who had them, in other words, had some advantage compared with those who didn’t.

Dr. Barreiro, who’s at the University of Montreal, has observed this pattern in many genes associated with autoimmune disorders. They’ve become more common in recent millenniums, not less. As population density increased with farming, and as settled living and animal domestication intensified exposure to pathogens, these genes, which amp up aspects of the immune response, helped people survive, he thinks.

In essence, humanity’s growing filth selected for genes that increase the risk of autoimmune disease, because those genes helped defend against deadly pathogens. Our own pestilence has shaped our genome.

The benefits of having these genes (survival) may have outweighed their costs (autoimmune disease). So it is with the sickle cell trait: Having one copy protects against cerebral malaria, another plague of settled living; having two leads to congenital anemia.

But there’s another possibility: Maybe these genes don’t always cause quite as much autoimmune disease.

Perhaps the best support for this idea comes from a place called Karelia. It’s bisected by the Finno-Russian border. Celiac-associated genes are similarly prevalent on both sides of the border; both populations eat similar amounts of wheat. But celiac disease is almost five times as common on the Finnish side compared with the Russian. The same holds for other immune-mediated diseases, including Type 1 diabetes, allergies and asthma. All occur more frequently in Finland than in Russia.