By Marton Dunai

BUDAPEST (Reuters) - Hungary announced plans on Wednesday to build a four-meter-high fence along its border with Serbia to stem the flow of illegal migrants, a move that triggered a swift rebuke from the United Nations Refugee Agency.

Hungary, a landlocked central European country of 10 million people, is in the EU's visa-free Schengen zone and thus an attractive destination for tens of thousands of migrants entering Europe through the Balkans from the Middle East and Africa. Most of them then move on to wealthier western Europe.

"The EU's countries seek a solution (for the problem of immigration) ... but Hungary cannot afford to wait any longer," Foreign Minister Peter Szijjarto told a news conference.

"We are talking about a stretch of border 175 km (110 miles) long, whose physical closure can happen with a four-meter high fence," he added.

The fence will evoke memories of the Cold War-era barriers -- including the Berlin Wall -- that separated communist eastern Europe, including Hungary, from the capitalist west.

Szijjarto said the fence would not violate any international agreements and that the government would hold a high-level meeting on July 1 with Serbia, which is not in the EU but wants to join, to discuss the plans.

According to the Hungarian Office of Immigration and Nationality (BAH) about 57,000 people have crossed into Hungary illegally so far this year, up sharply from 43,000 in all of 2014. Migration began to spike in the middle of last year.

Hungarian Prime Minister Viktor Orban's government, which is losing voters to the far-right Jobbik party, is under fire from the EU and human rights groups over its handling of immigration.

Orban has said an EU proposal to distribute migrants evenly across the 28-nation bloc "borders on insanity".

The U.N. Refugee Agency's regional spokesperson Kitty McKinsey condemned the fence plan.

"The right to seek asylum is an inalienable human right. So we are concerned that erecting a fence would place too many barriers to this right," McKinsey told Reuters.

Story continues

"SAFE COUNTRIES"

Szijjarto said Budapest would designate all EU member states and EU candidates such as Serbia as "safe countries", putting the onus on them to take responsibility for migrants crossing their territory. Of the seven countries bordering Hungary, only Ukraine is neither an EU member nor a candidate.

Hungarian government ministers have said they will block migrants arriving in the country from safe countries.

Serbian Prime Minister Aleksandar Vucic said he was surprised at the Hungarian decision and would make a detailed comment after Thursday's cabinet meeting.

"Nobody builds walls in a modern world you know, and particularly not in a part of Europe," Vucic told reporters during a visit to Oslo.

"We were very surprised, and also, we are not going to do the same to Macedonia as the Hungarians."

Most illegal migrants arrive in Serbia from Bulgaria, which is an EU member, or from Macedonia, which is not.

Bulgaria has built its own fence along a section of its 240-kilometre border with Turkey with the same aim of keeping out migrants and it has plans to extend it.

(Additional reporting Stine Buch Jacobsen in Oslo,; Editing by Gareth Jones)