Two of the victims were seriously injured and at least one suffered gunshot wounds, an SNCF spokesman said, adding that the assailant was armed with guns and knives.
The motives behind the attack were not immediately known.
The incident happened near Arras in northern France shortly after 1600 GMT and the gunman was arrested when the train stopped at the town's station, an SNCF spokesman told AFP.
French Interior Minister Bernard Cazeneuve was heading to Arras in the wake of the incident, his ministry said.
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.