Some passengers got off the train when it stopped in the countryside, including those who broke windows to escape, officials said. Ten people were injured, Spanish news agency Efe reported.
The Castellón provincial government tweeted a video of firefighters running for their lives on Wednesday as towering flames from the Bejís blaze roared behind them.
The forest fire is one of two still raging in eastern Spain.
South of the city of Valencia, a fire in the Val d’Ebo region has burned 11,500 hectares (28,000 acres) and forced more than 1,500 people to evacuate towns and villages since the weekend.
Area emergency services tweeted Wednesday afternoon that nearly 10,000 hectares (25,000 acres) have been burned in the Bejís fire and 1,500 people have left their homes.
Valencia regional president Ximo Puig said earlier that the Bejís fire had a perimeter of around 50 kilometers (30 miles) and the Val d’Ebo fire had a perimeter of 80 kilometers (50 miles). ).
The European Forest Fire Information System says 275,000 hectares (679,000 acres) have burned in forest fires so far this year in Spain. That’s more than four times the country’s annual average of 67,000 hectares (165,000 acres) since 2006, when the records began.
In neighboring Portugal, authorities said they were hoping to bring a forest fire under control which burned for 12 days and scorched large swaths of pine forest in the Serra da Estrela natural park.
However, officials have warned that another heat wave predicted for the region could complicate the task.
Smoke from the Portuguese fire reached the Spanish capital, Madrid, about 400 kilometers (240 miles) to the east on Tuesday.
Follow all AP stories on climate change and the environment at https://apnews.com/hub/climate-and-environment