Hungary's parliament has passed new legislation tightening asylum rules, and backed plans to erect a border fence to keep out migrants.
The new law allows the detention of migrants in temporary camps, the speeding up of asylum assessments and limiting the possibility for appeal.
The move was criticised by the UN and human rights groups.
Hungary has seen a rise in the number of migrants and asylum seekers in 2015, most of them entering from Serbia.
The government says about 72,000 migrants have entered the country so far this year, compared with 43,000 people in 2014.
The hope is that only "several dozen, or at most a few hundred" asylum seekers will be accepted in future, a senior government source told the BBC's Nick Thorpe.
The new legislation was passed easily in a 151-41 vote on Monday, with the backing of the governing Fidesz party and the far-right Jobbik party.
"Hungary is confronted with the biggest surge of migrants in its history, its capacities are overloaded by 130%," said Interior Minister Sandor Pinter.
Government spokesman Zoltan Kovacs told the BBC that from now on the Hungarian authorities would regard Serbia, Macedonia, Bulgaria and Greece as "safe" countries.
In practice this means that almost all asylum seekers who reach Hungary - a landlocked country - overland will be rejected, Nick Thorpe reports from Budapest.
He adds that most will not even get a chance to apply, because they would be stopped by the border fence, construction of which is expected to begin immediately.
According to Mr Kovacs, Hungary will handle each asylum application on its own merits, albeit in a fast-track procedure, and will comply with the 1951 UN Convention on Refugees.
The fence is to run the length of the 175km (109-mile) border with Serbia.
The UN and human rights groups have criticised Hungary's immigration proposals.
The regional representative of the UN High Commissioner for Refugees warned that the legislation would have devastating implications for thousands of people seeking safety in Hungary.
Refugees from the wars in Syria, Iraq, Afghanistan and Democratic Republic of Congo could see their applications rejected automatically, our correspondent says.
"Eighty per cent of these people are fleeing war and conflict," said the UNHCR's Babar Baloch. "This is a refugee crisis, but it's being wrongly described as a migrant crisis by the politicians here."