Macedonia has changed its asylum law to let migrants entering the country illegally avoid jail if they leave within three days.

Thursday's move follows a series of fatal accidents involving migrants traveling through Macedonia on the way to more prosperous European countries, following dangerous routes to avoid police arrest.

Macedonia has become a major transit route for thousands of Middle Eastern and African refugees and migrants who cross over from Greece. At least 25 have been killed by trains since January as they walked on railway tracks. Many others are robbed by criminal gangs.

The new law effective next week allows migrants to apply for temporary asylum at the border or the nearest police station. That will allow them to travel legally through the country for three days.