IDOMENI, Greece/SKOPJE, Nov 28 (Reuters) – Soldiers in Macedonia began erecting a metal fence on Saturday on the country’s southern border with Greece, described by an official as a “preventive” measure to better control the flow of migrants across the Balkans.

Soldiers drove metal poles around 3 metres 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 en route to western Europe this year.

Syrians, Afghans and Iraqis 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 senior Macedonian government official, who declined to be named, said the new fence was “just a preventive measure.”

“We are not closing the border completely,” the official said, describing it as an attempt to funnel the flow. “We will still allow the migrants from war-affected countries to pass.”

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.