President Trump had something in common with the other world leaders at the NATO summit in Brussels — an immigration emergency on their doorsteps.

The illegal immigration and border security crisis that tops Mr. Trump’s domestic agenda is part of a worldwide migration surge that is roiling governments across the Northern Hemisphere.

From Canada to Mexico to Britain and throughout Europe, governments are under pressure from their citizens to turn back a flood of refugees, asylum seekers and immigrants who cross the border illegally.

Whether its local governments chiding Canadian Prime Minister Justin Trudeau for inviting an onslaught of refugees to their communities or German Chancellor Angela Merkel being forced to slam shut her “open-door policy,” a public backlash against unchecked immigration has governments rethinking their border policies.

“The citizens of these countries start to resent the policymakers and bureaucrats and politicians who have not seen fit to enforce immigration laws and seem to be abdicating the country’s sovereignty to promote these feel-good asylum policies,” said Jessica M. Vaughan, director of policy studies at the Center for Immigration Studies.

The elected officials brought the crisis upon themselves with policies on asylum seekers, guest workers and even student visas that draw migrants to their borders, she said.

“They often are coming not so much because they are being pushed by conditions in their own country but because they are being pulled by the lure of loopholes in county’s asylum laws. Asylum is cover for migrating for better opportunity,” said Ms. Vaughan. “If we create the opportunity, people are going to take advantage of it.”

Mr. Trump is under fire in the U.S. for separating parents from their children who are among the tens of thousands of immigrants jumping the southern border each month. U.S. Border Patrol in June nabbed nearly 35,000 people entering the country illegally from Mexico.

Mr. Trump sees an easy solution. “Don’t come to our country illegally. Come like other people do. Come legally,” he said.

Leaders in other countries face a similar dilemma, balancing the urge to welcome refugees against the need to control immigration and protect citizens.

Victor Asal, a homeland security scholar at the University at Albany-State University of New York, said there is “no easy answer” to the refugee problem facing wealthy countries. He said the bigger danger came from populist revolts against immigration.

“It’s an easy tool for people who want to push ethnographic nationalist agendas,” Mr. Asal said.

With more than 3,000 refugees crowding facilities in Toronto officials in the province are blasting Mr. Trudeau for setting out the welcome mat in a tweet last year, saying Canada will welcome refugees turned away by Mr. Trump.

“This mess was 100 percent the result of the federal government, and the federal government should foot 100 percent of the bills,” said a spokesman for the Ontario government.

Mr. Trudeau shrugged off the criticism.

So far this year, the Royal Canadian Mounted Police caught more than 9,400 asylum seekers crossing the Canada-U.S. border. That’s on top of 20,000 refugees, mostly from Haiti, who arrived at the border last year saying they feared deportation in the U.S.

Mexico, historically a pass-through county for Central Americans headed for the U.S., finds itself wanting to turn back the tide of immigrants who sometimes end up staying in Mexico.

The European Union has struggled with a flood of refugees since 2015 as people fled war in Syria and violence in Africa. The numbers have subsided, but hundreds of thousands arrived last year and the effects of wave after wave of refugees continues to wash across the region.

Since 2014, about 650,000 immigrants have landed on Italian shores, with many of them taking advantage of open borders within the EU to travel to Germany, Britain and other countries.

The new populist government in Italy wants to refuse boats carrying refugees. Last week, a boat carrying 60 refugees was turned away from Italy and Malta, eventually landing in Barcelona, Spain.

Italian Interior Minister Matteo Salvini said the new government is not honoring past agreements to participate in EU sea rescues.

“With our government, the music has changed and will change,” said Mr. Salvini.

The immigration helped fuel the Brexit vote in the U.K. Now, British Prime Minister Theresa May is taking heat for engineering a “soft” exit from the EU that critics say doesn’t reclaim complete sovereignty over immigration.

To save her governing coalition, Ms. Merkel recently relented after years of bucking voters alarmed by the crime and cultural impact of the more than 1.4 million refugees entering Germany since 2015, mostly from war-torn Syria, Iraq and Afghanistan.

German Interior Minister Horst Seehofer this week presented a “master plan” for the refugee crackdown, including enhanced security on the German-Austria border, more “anchor centers” to process refugees and tougher penalties for asylum seekers who break the rules.