The train was traveling in the Valencia region on Tuesday night when the driver decided to reverse course because of the wildfire advancing from around the town of Bejís, further east.
Some passengers got off the train when it stopped in the countryside, including ones who broke windows to escape, officials said. Ten people were injured, Spanish state news agency Efe reported.
The government of Castellón province on Wednesday tweeted a video of firefighters running for their lives as towering flames from the Bejís fire roared behind them.
Other users tweeted videos said to be of the incident on the train.
On user said the video showed people fleeing on foot after the train headed towards the flames, in the direction of the town of Torás.
The wildfire is one of two still raging out of control in eastern Spain. South of Valencia city, a bigger fire around the Val d’Ebo area has forced more than 1500 people to evacuate towns and villages since the weekend.
Valencia regional President Ximo Puig said on Wednesday that the Bejís fire had a perimeter of some 50 kilometres and had burned some 4000 hectares. He said the Val d’Ebo blaze had a perimeter of 80 kilometres and had scorched some 11,500 hectares.
The European Forest Fire Information System said 275,000 hectares had burned in bushfires so far this year in Spain.
That’s more than four times the country’s annual average of 67,000 hectares since 2006, when records began.
In neighbouring Portugal, authorities said they hoped to bring under control a wildfire that had burned for 12 days and scorched large swathes of pine forest in the Serra da Estrela Natural Park.
Officials warned a new heat wave forecast for the area could complicate the task.
Smoke from the Portugal fire reached Spain’s capital, Madrid, about 400 to the east, on Tuesday.
– Reported with 9News Staff