This has put Sweden and Norway on opposite sides of an emerging debate: whether advanced welfare states designed for small and homogeneous societies in the mid-20th century are capable of absorbing large numbers of non-European foreigners.

In Sweden, a closely patrolled pro-immigration “consensus” has sustained extraordinarily liberal policies while placing a virtual taboo on questions about the social and economic costs. In Norway, a strong tradition of free speech and efficient administration has produced a hard-nosed approach about which refugees, and how many, to take in.

The Norwegian Foreign Ministry has calculated that because of all the social, health, housing and welfare benefits mandated by the state, supporting a single refugee in Norway costs $125,000 — enough to support some 26 Syrians in Jordan. And the Norwegian press has reported that following an alleged terrorist threat from abroad in July, Norway’s immigration authorities deported asylum seekers who raised security concerns.

Unlike the far-right Sweden Democrats, which have been shunned by other Swedish parties, Norway’s own anti-immigration party, the populist Progress Party, has entered a coalition government and makes its concerns heard. Solveig Horne, the minister of children, equality and social inclusion, and a member of the Progress Party, complains that Norway already has more asylum seekers than it can accommodate. “More and more are allowed to stay in Norway,” she told me in Oslo last month. “But many communities are saying, ‘Wait. We have to be sure we can integrate the people we already have.’ ”

This is just the kind of blunt talk that is strictly avoided in Sweden. Take the comments of the incumbent prime minister, Fredrik Reinfeldt, a few weeks before last Sunday’s election. He asked voters to “open their hearts” to Syrian refugees, even though the escalating cost of supporting them would preclude further welfare benefits for Swedes. The comment caused an outcry — not because it seemed to favor refugees over Swedes, but simply for suggesting that refugee policy needed to be considered on economic grounds.

And yet there is plenty to discuss. Mr. Ranstorp, the counterterrorism official, described a recent visit to Angered, an overwhelmingly immigrant suburb of Gothenberg, the second-largest city in Sweden: “I found extremism, but I also found overcrowded housing, drug gangs controlling the area, police not reporting crime, people living in drab apartment blocks with no shops, a parallel justice system.”

One perverse result of Sweden’s refusal to engage these problems, Mr. Ranstorp and others say, is to have ceded the immigration debate to a far-right party whose leader has likened Islam to “the worst threat facing Sweden since World War II.”