A wave of nationalism seems to be sweeping across rich countries, from the UK’s ill-tempered exit of the European Union to the “America first” policies of US presidential candidate Donald Trump and the rise of populist, anti-immigrant movements in France, Eastern Europe, and elsewhere.

Drivers of nationalism include a slow economic recovery, an increase in people displaced across borders, and anxiety about terrorism, according to Harun Onder, an economist at the World Bank. Another factor, which is perhaps not as appreciated, is age. Many rich nations are in the grips of a big demographic shift towards older populations, and aging populations experience economic pressures that can lead to more nationalistic tendencies.

In the UK referendum on EU membership, age was one of the biggest factors in how people voted, with three-quarters of young people opting to remain while 60% of those over 65 wanted to leave. Many of the young on the losing side of the vote were bewildered by the shift towards insularity and the cutting of ties, which runs counter to their experience as hyper-connected global citizens.

Older people might be expected to vote for more cautious, protectionist policies than younger people with a greater appetite for risk, openness to learning new skills, and fewer commitments tying them to a specific place. But Onder’s research shows that the economic effects of aging populations are reflected in rising nationalism across the board, not just in the “gray vote.”

Why? Aging populations become more dependent on imports, and that can make the economy a weaker trade partner. Older people consume more services, like care, and fewer consumer goods, like smartphones. As a result, makers of goods may move abroad to get closer to more lucrative markets, so their former homes have to import the products they once purchased locally.

Many services have to be delivered domestically, and these companies will benefit from rising demand. But care homes are often less innovative than smartphone makers, so aging, service-oriented economies risk becoming less productive in the long term. That, along with dwindling prospects for manufacturing-related jobs, can dampen earnings for large groups of workers. In former industrial centers in the UK, for example, this has fueled hostility towards outsiders—like migrants from poorer EU countries—who are perceived as taking increasingly scarce jobs from locals and generally depressing wages for low-skilled and entry-level positions.

In this context, cutting immigration, imposing tariffs, and erecting other trade barriers becomes an increasingly popular means to protect beleaguered domestic firms and workers. But if this provokes retaliation by trade partners, the older, less competitive economies have more to lose. “Yes, some firms would come back home, but the losses from paying more for imports and earning less from exports are much greater than these gains,” Onder writes.

“It is interesting to see that rising nationalism might have deep roots in demography,” Onder adds. “Going forward, more effort needs to be devoted to understanding the relationship between the two.” Indeed, if aging societies are naturally inclined to nationalism, we’re only experiencing the start of a much longer-lasting trend.