In the summer of 2015, at the height of the migrant influx into Europe, Hungary built a razor-wire fence along the border with Serbia, to the south, to try to stanch the flow of people moving through the Balkans. That move caused a huge outcry, but Mr. Orban said the fence was an effective deterrent.
The new law, which Parliament approved by a vote of 138 to 6, with 22 abstentions, would allow the government to detain asylum seekers, including children, for potentially long periods of time in mobile housing units, which look like shipping containers, in camps surrounded by razor-wire fence, while their applications were processed.
Human rights advocates, including the United Nations refugee agency, condemned the move.
The agency said that the new law would have “a terrible physical and psychological impact” on refugees, and it emphasized that Hungary had a legal obligation to consider less coercive measures.
“There is a global tendency to tighten the rules and conditions for asylum seekers all over the world, and this is happening in Europe and the United States,” said Erno Simon, a spokesman for the United Nations agency in Hungary. He added, “Detainment in containers is particularly detrimental for children.”
Some of Mr. Orban’s antimigrant talk seems to be for political show. Relatively few migrants have tried to settle permanently in Hungary; a vast majority who entered or tried to enter in recent years were hoping to use the country as a gateway to more welcoming countries, like Germany and the Netherlands.
Todor Gardos, a researcher at Amnesty International in London, said that the new law in Hungary violated European Union regulations that prohibit detaining an individual just because they have claimed asylum. “The blanket detention of all asylum seekers breaches the law, which requires that detainment be justified on an individual, case-by-case basis,” he said.
Hungary’s latest move comes as countries across Europe, buffeted by the rise of populist parties, have been seeking ways to discourage migration. More than one million refugees and migrants streamed into Europe last year, fleeing war, conflict and poverty in the Middle East and Africa.
Denmark passed a law requiring newly arrived asylum seekers to hand over valuables, including jewelry and gold, to help pay for their stay in the country.
Even in relatively liberal Germany, where more than a million migrants have arrived since early 2015, calls to expel migrants who are in the country illegally have been intensifying. The cabinet recently approved attaching electronic bracelets to migrants who are in the country illegally and tapping their cellphones if they are deemed to be a potential threat.
In France, the far-right presidential contender Marine Le Pen, who has hailed Mr. Trump’s victory as a harbinger of her own success, has promised to crack down on foreigners, saying that the interests of French citizens must come first.
Against this backdrop, human rights advocates say that the political and legal climate in Europe is becoming more hostile to immigration, mirroring the animosity and populism on the other side of the Atlantic.
Also on Tuesday, the European Court of Justice defied the advice of one of its own advocates general by ruling that European Union member states were not obliged to issue visas to people who planned to seek asylum in their countries, even if they were vulnerable to inhuman treatment or were threatened with torture.
The advocate general, Paolo Mengozzi, said last month that European Union countries should issue humanitarian visas if there were substantial grounds to conclude that “a refusal would place persons seeking international protection at risk of torture or inhuman or degrading treatment.” Such advice is nonbinding but is usually followed.
Nevertheless, the court ruled that European Union law did not require member states to grant humanitarian visas but were “free to do so on the basis of their national law.”
The ruling came after a Syrian family of five from Aleppo had applied for visas at the Belgian Embassy in Beirut, Lebanon, in October 2016, with the aim of traveling to Belgium and applying for asylum there. After the visa application was refused, the family complained to the Belgian Asylum and Immigration Board, which, in turn, referred the case to the European Court of Justice.
Human rights advocates said the court’s ruling threatened to put the most vulnerable in harm’s way. But others countered that a blanket requirement to issue humanitarian visas would have enabled people to apply for asylum at embassies around the world, stretching the immigration services of countries that are already struggling to cope.