Hungary's parliament has approved the automatic detention of all asylum seekers in container camps at the country's borders, prompting "deep concern" from the UN Refugee Agency.
The legislation was approved by a large majority of lawmakers.
Prime Minister Viktor Orban said it was a response to recent terror attacks in Europe carried out by migrants.
Speaking at a swearing-in ceremony for 450 new border police, he said Hungary was "under siege".
"The migration flow has only slowed, but it is not over," Mr Orban said. "We have gained time to strengthen our lines of defence."
He called immigration "the Trojan horse of terrorism", adding: "If the world sees that we can defend our borders... then no one will try to come to Hungary illegally".
The prime minister said the arrival of Muslim migrants endangers Europe's Christian culture and identity.
"Those readying for the journey do not want to live according to our ways and culture, but according to their own - only with a European quality of life," he said in Budapest.
Under the new measures, all asylum seekers entering Hungary - and those currently in the country - will be confined in camps built from shipping containers while their asylum applications are processed.
Appeals against rejected applications will be fast-tracked, and those denied entry may have to cover their own detention costs.
Human rights groups including Amnesty International have raised grave concerns about the crackdown, calling it "xenophobic, fear-mongering propaganda".
"There are hardly 400 asylum seekers in the country," said a statement issued by seven groups, including Amnesty International Hungary, the Hungarian Helsinki Committee, and MigSzol, the Migrant Solidarity Group of Hungary.
Gauri Van Gulik, Amnesty International's Deputy Director for Europe, said the move was "beyond the pale".
"These measures will even be applied to children, a flagrant violation of international and European law," she said.
"Dumping all refugees and migrants into containers isn't a refugee policy - it's avoiding one."
The UN Refugee Agency said it was "deeply concerned" about the detention of asylum seekers.
"This new law ... will have a terrible physical and psychological impact on women, children and men who have already greatly suffered," it said in a statement.
Hungary's nationalist prime minister has maintained a hardline stance on migration for some years.
In 2015, when the country became a transit state for asylum seekers en route to Germany and other EU nations, he responded by building razor wire fences on the borders with Serbia and Croatia.
Some 400,000 migrants passed through Hungary that year before the fences were in place.
A second, 150km (93 mile) fence on the Serbian border is scheduled for completion in May, equipped with night cameras and heat and movement sensors.
In October last year, Hungary held a referendum on whether to accept mandatory EU quotas for relocating migrants.
The EU had asked it to accept 1,294 refugees.
The referendum was ultimately invalid, as while 98% of those who took part wanted to reject the EU plan, the turnout fell short of the required 50% threshold.
In 2016, Hungary registered 29,432 asylum claims and accepted just 425 asylum seekers.
By contrast, Germany took in 280,000 in 2016.