French investigators were on Saturday interrogating a man who was overpowered by three young Americans after he opened fire with a Kalashnikov on a train between Amsterdam and Paris.
The suspect is thought to be a 26-year-old of Moroccan origin who had lived in Spain, said sources close to the investigation. He was known to the French authorities after being flagged as a potential jihadist by Spanish intelligence services.
Spanish daily El Pais said he moved to France last year and had visited Syria.
Armed with a Kalashnikov assault rifle, an automatic pistol, nine cartridge clips and a box-cutter, the man opened fire on board the TGV train just after it crossed from Belgium into France on Friday evening.
But the attack was quickly stopped when a group of young Americans on holiday - two of them off-duty soldiers - charged the gunman and overpowered him.
"I looked back and saw a guy enter with a Kalashnikov. My friends and I got down and then I said 'Let's get him,'" Alek Skarlatos, a 22-year-old member of the National Guard in Oregon, told reporters.
Spencer Stone, who is reportedly in the US Air Force, was the first to reach the gunman - and was slashed in the neck and hand with a box-cutter during the confrontation.
"At that point I showed up and grabbed the gun from him and basically started beating him in the head until he fell unconscious," said Skarlatos, who recently returned from service in Afghanistan.
The third American, student Anthony Sadler, said the attacker "didn't stand a chance."
"As soon as we saw him, we all ran back there. It all happened really fast," said Sadler.
"He didn't say anything. He was just telling us to give back his gun. 'Give me back my gun! Give me back my gun!' But we just carried on beating him up and immobilized him and that was it."
Stone was taken to hospital along with another unnamed American passenger, who was hit in the shoulder with a bullet.
Mobile phone footage from inside the train and played on several TV stations shows the suspect, a skinny man wearing white trousers and no shirt, flattened on the floor of the train with his hands and feet tied behind his back.
A Kalashnikov is seen leaning against a seat and blood is visible on a window.
"I'm just a college student," said Sadler. "I came to see my friends for my first trip to Europe and we stop a terrorist. It's kind of crazy."
President Barack Obama praised the young men, saying "it is clear that their heroic actions may have prevented a far worse tragedy."
French Interior Minister Bernard Cazeneuve said the group showed "great bravery."
"Without their cool-headed actions we could have been faced with a terrible incident," he said.
The motives for the shooting were not immediately known, although French prosecutors said counter-terrorism investigators had taken over the probe.
France has been on high alert since Islamist gunmen went on the rampage in January, murdering 17 people in Paris.
In June, a man beheaded his boss and tried to blow up a gas plant in southern France in what prosecutors say was an attack inspired by the Islamic State group.
The man began shooting at 5:50 p.m. local time, train operator Thalys said.
He was arrested 10 minutes later when the train, with 554 passengers on board, stopped at Arras station in northern France, a railway spokesman said.
One of the passengers, who asked to be identified only as Damien, 35, said he had heard the gunman shooting but initially thought the sound came from a toy.
"The man stopped between two carriages, fired and it made a click-click-click sound, not at all like in the films," he said, still clearly shocked.
French actor Jean-Hugues Anglade, who appeared in the 1986 cult film "Betty Blue" staring Beatrice Dalle, suffered minor injuries as he tried to activate the train's alarm, a spokesman for SNCF said.
The gunman had probably boarded the train in Brussels, a police source said.
In May last year, four people, including two Israeli tourists, were murdered when a Muslim terrorist opened fire at the Jewish Museum in Brussels.
AFP contributed to this report.