Hungary approved plans on Tuesday to detain migrants in camps on its border, state newsagency MTI said, a step which the United Nations said violates European Union law and will have a "terrible physical and psychological impact" on asylum seekers.
The measures, passed by parliament, will also tighten controls on Hungary's border, which has been a focal point of Europe's migration crisis since 2015.
The southern border with Serbia marks the external frontier of the EU's passport-free Schengen area, and hundreds of thousands of people have crossed into the country.
Prime Minister Viktor Orban sought to justify the move, saying Hungary had to act to defend itself and describing the influx of migrants - many of them fleeing conflict in the Middle East and Africa - as a "Trojan horse for terrorism".
Orban's chief of staff said last month that Hungary planned two or three camps along its southern border, where migrants will be kept while their applications for asylum are processed.
Migrants whose applications are not immediately approved will not be allowed to move freely around Hungary but will be detained in camps that they can only leave outward, toward Serbia, according to the bill approved by parliament. UNHCR spokeswoman Cécile Pouilly said that would effectively condemn asylum seekers, including children, to prolonged detention in shipping containers surrounded by barbed wire.
Expanding an 8-kilometre (5-mile) zone along the border where summary expulsions have been the practice since last summer, police can now detain illegal migrants anywhere in the country and return them to the Serbian border to be expelled.
"Nobody can step onto Hungarian or European Union soil without a permit," interior minister Sandor Pinter said in the bill.
In a speech to newly appointed border guards on Tuesday, Orban described a country under siege.
Although the daily tally is down significantly, Hungarians "cannot lean back in our chairs... we merely gained some time in between two major waves (of migrants)."
The country must use this time to fortify its defences, he said. Hungary has begun to put in place the second line of a"smart fence" along the Serbian border, complete with electroshock, surveillance and audio-visual warning systems.
Orban added the EU "made this work more difficult, so we can only count on ourselves, we need to defend our own borders...This will remain on the agenda until everyone admits that migration is a Trojan horse for terrorism."
"That is the reality, which cannot be pasted over by any rose-coloured human rights dream talk."
UNHCR's Pouilly said the number of asylum applications in Hungary had fallen sharply from 177,000 in 2015 to 29,000 last year, with just 912 in the first two months of 2017.
All asylum seekers, including those already in the country, would be kept in a transit zone where the detention centres are located, she said.
"In practice, it means that every asylum-seeker, including children, will be detained in shipping containers surrounded by high razor wire fence at the border for extended periods of time," Pouilly said in a statement.
"This new law violates Hungary's obligations under international and EU laws, and will have a terrible physical and psychological impact on women, children and men who have already greatly suffered."