With both countries also turning away from multilateral trade agreements, China has the opportunity to step in and play an even bigger role in the global economy. And Russia has seen an opening to expand its influence in Europe, where rising nationalism has threatened to fracture the European Union.

Mr. Trump and the Brexiteers have ridden a nationalist tide in their countries as well, using a potent anti-immigration message to appeal to mostly white voters who yearn for a more homogeneous society that no longer exists.

In Britain, immigration has provided an electric current to conservative politics since at least 1968, when the lawmaker Enoch Powell delivered a seminal speech calling for immigrants to be repatriated. Quoting a Greek prophecy of “the river Tiber foaming with much blood,” Mr. Powell’s speech is credited with propelling the Conservative Party to victory in the general election of 1970, though it also turned Mr. Powell into a political pariah.

Opposition to immigration spiked over the last two decades as Britain was hit with a series of terrorist attacks by Islamist militants and watched as migrants from Syria, Libya and other war-torn countries flooded across Europe.

In the United States, where the right was once preoccupied by social issues like abortion and same-sex marriage, immigration surged as an issue because of the changes wrought by globalization. Manufacturing jobs moved overseas, where labor was cheaper, while immigrants took both unskilled and high-tech jobs previously held by Americans.

By 2008, the financial crisis had wiped out millions of jobs, keeping people out of work for years and deepening the sense of grievance among many Trump supporters that immigrants were working for less and robbing them of their livelihoods.