More than 500 passengers were on board the trains when the incident occurred in the province of Toledo, south of Madrid.