Migrants on the Greek-Macedonian border have attacked police with stones, enraged by the sight of Macedonian authorities erecting a fence along the border.

Authorities said 18 Macedonian officers were injured in the brief but intense clashes on Saturday. Most of them received minor injuries but two were hospitalised in the nearby town of Gevgelija, Macedonia’s interior ministry said.

There was no official tally of injured migrants, although Macedonian police targeted them with stun grenades and plastic bullets. Doctors from the Red Cross and other non-governmental organisations said they treated 20 people for head injuries and breathing problems.

Tensions on the border were compounded by the accidental electrocution of a 24-year-old Moroccan man at the top of a train carriage. The man suffered severe burns, prompting anger among his compatriots, many of whom have been stranded at the border since Macedonia decided earlier this month, along with Serbia, Croatia and Slovenia, to let through only those from the “warzone” countries of Afghanistan, Iraq and Syria.

More than 600,000 refugees and other migrants from the Middle East, Africa and Asia have entered Europe through Greece this year, many after making the short sea crossing from Turkey. Most of them continue on a long trek through the Balkans toward the promised lands of central and northern Europe.

The 24-year-old is in a serious condition, with extensive burns, Greek police said, and has been transferred to a hospital in the city of Thessaloniki, 80 kilometres (50 miles) south of the border.

Migrants hurl stones at Macedonian policemen during clashes as the migrants protest against the building of a metal fence at the Greek-Macedonian border. Photograph: Milos Bicanski/Getty Images

Moroccan nationals allegedly formed the bulk of the about 250 people who started throwing stones at Macedonian police. Also among the 800 who are stuck at the border are citizens of Algeria, Tunisia, Lebanon, Yemen, Iran, Pakistan, Bangladesh, Somalia and Congo.

The clash ended in less than an hour when other migrants intervened, holding white clothing as a sign of peace.

Macedonian government spokesman Aleksandar Gjorgjiev said that the country has started to erect a fence on its southern border with Greece in order to prevent illegal crossings and to channel the flow of migrants through the official checkpoint.

Gjorgjiev said “the border will remain open and all migrants from the war-affected zones will be allowed to enter.”

The migrants are camped along the railway tracks, blocking rail traffic for the 11th consecutive day.

“I have been here for 10 days with my two sons. We have decided to return to Athens and see what we will do,” said 41-year-old Fatemeh, from the Iranian city of Ahwaz. She declined to give her last name, for fear of reprisals.

“There is no way to return to Iran, only prison awaits us,” she said. “We understand that the Syrians, the Afghans and the Iraqis are at war, but we also have a big political problem. There is no freedom in our country.”