Soldiers drove metal poles around 3 meters high into the cold, muddy ground, building a barrier similar to that erected by Hungary on its southern border to keep out the hundreds of thousands of migrants who have crossed the Balkans this year.

Soldiers in Macedonia began erecting a metal fence on Saturday on the country's southern border with Greece, but the government said it had no plans to seal off access to refugees fleeing war and heading to western Europe.

Migrants walk towards the transit camp in Gevgelija, Macedonia, after entering the country by crossing the border with Greece, September 11, 2015.

Syrians, Afghans and Iraqis fleeing conflict are flowing largely unimpeded across Balkan borders having landed by boat in Greece from Turkey.

But for the past two weeks, countries on the route including Macedonia have begun turning back migrants of other nationalities, leading to a chaotic buildup at the Macedonian-Greek border and days of protests by Iranians, Pakistanis, Moroccans and others.

Two days ago, protesters tried to storm police lines, breaking through a flimsy barrier into Macedonia, an impoverished former Yugoslav republic.

A government spokesman said the aim of the new fence was "to direct the inflow of people towards the controlled points for their registration and humane treatment."

"We would like to underline that the border will remain open," said spokesman Aleksandar Gjorgjiev. "We will allow passage for the people who come from war-affected regions as we have done thus far."

European Union member Hungary in September and October sealed its own southern border to migrants, calling them a threat to the security, prosperity and "Christian values" of Europe.

That diverted them into Croatia and Slovenia en route mostly to Germany, which is struggling to cope. Germany expects roughly 1 million refugees and migrants to arrive this year alone.

Follow us on Twitter: @CNBCWorld

