VELES, Macedonia -- A group of migrants trying to reach European opportunity via what's billed by smugglers as a "safe" route -- trekking along train tracks through the Balkans -- was hit by an overnight train in a remote river gorge in Macedonia, killing 14.

The deaths of the undocumented migrants from Africa and Asia underscore how, even as tens of thousands risk drowning in the Mediterranean to reach European shores, many others gamble with their lives by taking perilous overland journeys to reach Hungary, a popular back door to the 28-nation European Union.

Railway officials said many of those killed Thursday night had stopped to rest after an exhausting hourslong hike and were sleeping on the tracks when the train plowed into them.

The overland route from Greece through Macedonia and Serbia has soared in popularity over the past two years as migrants seek a less dangerous path than the sea crossing from North Africa to Italy.

Trains killed 40 migrants last year, usually in groups of one or two, compared to the more than 1,300 lives lost in the Mediterranean over the past three weeks alone -- a horrifying statistic that has put 2015 on track to be the deadliest year ever for the sea crossing.

The Balkans smuggling route follows railway lines through most of the 200-kilometre hike through Macedonia, and authorities say it was only a question of time before so many trekkers would die in a single train accident.

The rail line includes narrow wooden bridges and two long tunnels through mountains that can leave migrants trapped with no way of escape, as well as frequent riverside bends that conceal the sight and sounds of oncoming trains.

Thursday's accident occurred around 10:30 p.m. on a narrow stretch of tracks sandwiched between the Vardar River and a steep slope. The express train from Thessaloniki, Greece, to the Serbian capital of Belgrade was about 10 miles northwest of the central Macedonian town of Veles when the train's engineer spotted a group of about 100 migrants on the tracks in the dark, meters ahead.

"At the time that the train struck the group of migrants, they were resting and sleeping on the tracks," said Macedonian Railways manager Nikola Kostov. "The train driver honked and tried to stop, but it was too late and the train hit the group of migrants who weren't able to leave the tracks."

Kostov said the train was observing the local speed limit and described the stretch of track as "dangerous and unapproachable" for pedestrians.

Though Kostov did not give a precise speed, the schedule shows that the train does not typically travel quickly, taking more than 14 hours to cover 645 kilometres, averaging just 45 kph.

Authorities said the 14 dead appeared to be mostly Somalis and Afghans in their 20s, though other details remained uncertain -- not surprising, given that migrants often travel without IDs to complicate deportation efforts if caught. Somalis and Afghans are among the top nationalities using the Balkans route, along with Syrians fleeing civil war in their homeland.

Police detained nine migrants who remained at the scene Friday morning and questioned them about what happened and the identities of the dead. They said survivors described clambering up rocky slopes or clinging to bushes on the riverbank to escape the train.

The Veles prosecutor, Slavica Temelkovski, said the detained migrants were mostly relatives or friends of the dead and had identified themselves and the victims as being from Somalia and Afghanistan.

Tentative plans were put in place to bury the dead Saturday at Veles' Muslim cemetery on the presumption that, barring authentication to the contrary, all came from predominantly Muslim countries.

"This city is in disbelief," said Veles Mayor Slavco Cadiev. He said Veles residents over the past year had grown used to seeing hundreds of migrants pass through the town at once, usually sticking close to the rail lines.

Veterans of the Balkans route have told The Associated Press that following the train tracks in Macedonia is one of the most nerve-racking parts of what can be a monthslong journey involving detentions and deportations back to Greece to start the journey over.

Smugglers usually instruct migrants to travel the tracks at night, despite the increased risk of being hit by trains, because they are less likely to be spotted by authorities in the darkness.

For many, the Balkans route starts in Turkey, where migrants pack into small boats that are often piloted by migrants themselves and abandoned once they reach the nearest Greek island. That journey, because of overcrowding and the inexperience of boat operators, is often the most dangerous part of the journey -- a reality underscored this week when a wooden trawler carrying about 90 migrants broke up as it ran aground on the Greek island of Rhodes, killing three on board, including a boy.

Since February, the AP has followed a group of 45 West African migrants using the Balkans route. As they gathered at the Macedonian border in March, a smuggler warned they could easily be killed by a train if they didn't break up into small groups with a spotter at the front and the back, to shout alerts to the others.

When walking at night on the tracks, migrants say, it can be hard to distinguish the wooden ties from stony gaps, never mind tell where the river is and how steep the falls might be on either side. Painful dives and tumbles into mud or gravel to avoid trains are common.

"When trains come, they don't honk. It's woods. There's nobody there," said Hamed Kouyate, an 18-year-old from Ivory Coast who completed the Balkans route this month after a two-week trek, a brief police detention and other setbacks.

Kouyate said all members of his group struggled to see in the often moonless night and many suffered injuries from falls. He said they often were slow to react to trains because of mental and physical exhaustion. At one point, he said, one woman with an injured foot had to be pushed by others out of the way of an oncoming train.

"When you're on the tracks, you're afraid all the time," he said in a telephone interview from France, where he arrived this week.

"You're afraid because from one minute to the next, there might be a train."