According to initial information from investigators, at least two of the men who tackled the gunman were American troops who had apparently heard him loading his weapons in a toilet cubicle and confronted him after he came out.
Two people were wounded in the incident, with the Pentagon confirming that one was a member of the US military. The gunman had a Kalashnikov, an automatic pistol and a box cutter, one police source told news agency AFP.
The suspect, who was arrested when the train stopped at the northern French town of Arras, was a 26-year-old from Morocco or of Moroccan origin who was known to the intelligence services, French investigators said.
Footage taken moments after the suspected terrorist was overpowered
US President Barack Obama praised the passengers for their actions.
“The president expressed his profound gratitude for the courage and quick thinking of several passengers, including US service members, who selflessly subdued the attacker,” a White House official said. “Their heroic actions may have prevented a far worse tragedy.”
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, killing 17 people in Paris.
“I condemn the terrorist attack on the Thalys (train) and express my sympathy to the victims,” Belgian Prime Minister Charles Michel said on Twitter of the incident, which occurred while the train was in Belgium.
The man began shooting at 5.50 pm (1550 GMT), train operator Thalys said.
The gunman was arrested 10 minutes later when the train, with 554 passengers on board, stopped at Arras station where armed police were waiting, a spokesman for the French state rail company SNCF told AFP
The Pentagon said one of those hurt was a member of the US military but his injuries were not life-threatening.
One of the passengers on the train, 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.
“Then the man, who was bare-chested, returned to carriage 12 and someone in a green T-shirt, with a shaved head, saw him and jumped on him and pinned him to the ground.”
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. Police searching the train later found at least one bullet casing, according to a source familiar with the matter.
One victim was hit by a bullet. He was taken by helicopter to a hospital in Lille.
The second suffered cuts to his elbow caused by a box cutter and a broken finger, and was hospitalised in Arras, a source familiar with the matter said.
There was no immediate confirmation that they were the men who had subdued the suspect. A source close to the investigation said later that a third member of the US military was also involved but uninjured in the attack.
Spanish daily El Pais cited anti-terror sources as saying the suspect had lived in Spain for a year until 2014, when he moved to France. The newspaper also reported that he had visited Syria.
French Interior Minister Bernard Cazeneuve, who went to Arras in the wake of the incident, also praised the Americans who had subdued the suspect.
They showed “great bravery in very trying circumstances”, he said. “Without their cool-headed actions we could have been faced with a terrible incident.
French President Francois Hollande said “everything is being done to shed light” on the shooting.
Witness Nicolas Martinage, 17, said he had seen the victims being taken off the train in Arras.
“There were two people with blood on them, one had a wound to the eye. The second was around 30 and had a bandage on his shoulder. Both men were on stretchers,” he told AFP.
One passenger, Patrick Arres, 51, said when the train pulled into Arras station he saw more than 30 armed police. “They were looking for someone, people were scared.”
France remains on edge after Islamic extremists attacked the satirical magazine Charlie Hebdo and a Jewish supermarket in Paris in January in a spree that killed 17 people and shocked the world.
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.