Bodies covered in blankets lay next to the overturned carriages as smoke billowed from the wreckage. Firefighters clambered over the twisted metal trying to get survivors out of the windows, while ambulances and fire engines surrounded the scene.
The government said it was working on the hypothesis the derailment was an accident - although the scene will stir memories of 2004's Madrid train bombing, carried out by Islamist extremists, that killed 191 people. Sabotage or attack was unlikely to be involved, an official source said.
The train operated by state rail company Renfe with 247 people on board derailed on the eve of the ancient city's main festival in honour of Saint James when thousands of Christian pilgrims from all over the world pack the streets.
"It was going so quickly. ... It seems that on a curve the train started to twist, and the wagons piled up one on top of the other," passenger Ricardo Montesco told Cadena Ser radio station.
"A lot of people were squashed on the bottom. We tried to squeeze out of the bottom of the wagons to get out and we realised the train was burning. ... I was in the second wagon and there was fire," he added.
Prime Minister Mariano Rajoy, who was born in Santiago de Compostela, will visit the site on Thursday morning, his spokeswoman said.
"In the face of a tragedy such as just happened in Santiago de Compostela on the eve of its big day, I can only express my deepest sympathy as a Spaniard and a Galician," Rajoy said in a statement.
Santiago de Compostela's tourism board said all the festivities, including Wednesday's traditional High Mass at the centuries-old cathedral, were cancelled as the city went into mourning.
Clinics in the city were overwhelmed with people flocking to give blood, while hotels organised free rooms for relatives. Madrid sent forensic scientists and hospital staff to the region on special flights.
"The scene is shocking, it's Dante-esque," he said in a radio interview.
The train was travelling from Madrid to Ferrol on the Galician coast when it derailed, Renfe said in a statement.
The disaster happened when Spain is struggling to emerge from a long-running recession marked by government-driven austerity to bring its finances into order. Firefighters called off a strike to help with the disaster, while hospital staff, many operating on reduced salaries because of spending cuts, worked overtime to tend the injured.
The city's main festival focuses on St James, one of Jesus' 12 disciples whose remains are said to rest in the city and who is patron saint of Galicia.
The apostle's shrine there is the destination of the famous El Camino de Santiago pilgrimage, followed by Christians since the Middle Ages.
The derailment happened less than two weeks after six people died when a train came off the tracks and hit the platform at a station in central France.
That accident may have been caused by a loose steel plate at a junction, French train operator SNCF said.
An official source said no statement would be made regarding the cause of the Spanish derailment until the black boxes of the train were examined, but said it was most likely an accident.
"We are moving away from the hypothesis of sabotage or attack," he said.
It was one of the worst rail accidents in Europe over the past 25 years.
In November 2000, 155 people were killed when a fire in a tunnel engulfed a funicular train packed with skiers in Austria.
In Montenegro, up to 46 people were killed and nearly 200 injured in 2006 when a packed train derailed and plunged into a ravine outside the capital, Podgorica.
In Spain itself, 41 people were killed the same year when an underground train derailed and overturned in a tunnel just before entering the Jesus metro station in Valencia.
(Reporting by Inmaculada Sanz, Sonya Dowsett, Sarah White, Andres Gonzalez, Blanca Rodriguez and Julien Toyer; Writing by Sonya Dowsett; Editing by Sarah White, Andrew Heavens and Peter Cooney)