PARIS — Two women were killed in southern France on Sunday by an assailant armed with a knife, in an attack that forced the evacuation of a major train station, the authorities said.

The assailant was fatally shot by a military patrol after killing the women in front of the Saint-Charles train station in the Mediterranean port city of Marseille. The attack interrupted train service and unnerved the country as it debated the government’s new security bill.

The Paris prosecutor’s office, which handles terrorism cases nationwide, said on Sunday that it had opened a terrorism investigation, but the authorities said the assailant’s motives were not entirely clear.

“This act could be of a terrorist nature, but at this hour we cannot affirm it,” said Gérard Collomb, the French Interior minister, who is in charge of domestic security.

Mr. Collomb, who arrived in Marseille on Sunday evening and spoke to reporters at the train station, did not identify the assailant or the two victims, saying only that they were “young women.”

The Islamic State claimed responsibility for the attack several hours later, calling the assailant one of its “soldiers.”

The group’s Amaq news agency said the man had been inspired by calls to carry out attack in Western countries. In 2014, ISIS called on sympathizers to commit violence using any means available, including stabbings, in those countries whose militaries were fighting the terror group in Iraq and Syria.

The group’s claim of responsibility could not be independently verified.

Asked about reports that the attacker yelled “Allahu akbar,” or “God is greatest” in Arabic, at the moment of the attack, Jean-Claude Gaudin, the mayor of Marseille, said that “a certain number” of witnesses had said they heard him do so, but he added that they were still being interviewed by the police for further details.

“We have video images that will enable us to assess the situation,” Mr. Collomb said, referring to security camera footage in the station. “What is strange on the video is that the person starts to commit his crime on a first person, then he runs away, and then he turns back to kill the second person.”

A military patrol that had rushed to the scene after hearing cries of panic and seeing people running fired warning shots at the attacker, Mr. Collomb said, and then shot and killed him when he rushed at them.

Soldiers and armed police officers with protective gear barred access to the train station for much of Sunday afternoon, and the national railway operator urged travelers to avoid the station, but the authorities said later in the day that train service was slowly returning to normal.

France has been on high alert for acts of terrorism since 2015, after a string of attacks that killed more than 230 people. The deadliest attack was an assault in November 2015 by coordinated teams of Islamic State operatives who killed 130 people in and around Paris, prompting officials to declare a state of emergency.

The state of emergency, which enables the authorities to raid homes and place people under house arrest without the authorization of a judge, has been renewed several times and will end on Nov. 1.

But Parliament is expected to vote soon on a bill that would give security forces additional powers, some similar to those in the state of emergency, to monitor suspects, conduct raids and search bags or vehicles. Civil rights groups have criticized the legislation.

In a statement on Sunday evening, Édouard Philippe, the French prime minister, expressed “anger and outrage” after the attack and praised the soldiers who had “neutralized the criminal and stopped his killing spree.”

So far in 2017, there have not been large-scale attacks like the ones that struck Paris in 2015 and Nice in 2016, but France has grown wearily accustomed to smaller, sporadic attacks, especially against police officers and soldiers patrolling sensitive or crowded sites.

In September, a man wielding a knife was arrested after he attacked a military patrol in one of the biggest metro stations in Paris; but no one was injured. In August, a driver plowed into a military patrol in Levallois-Perret, a suburb just north of the capital, injuring six soldiers.

Other attacks have been carried out by mentally ill residents, who sometimes imitate acts of terrorism, according to officials.

In August, a man with a history of psychiatric disorders rammed a vehicle into two bus stops in Marseille, killing one woman, but the authorities said the episode was not related to terrorism.

In September, four American college students traveling through the Saint-Charles station were attacked with acid by a psychologically disturbed woman, officials said.

A version of this article appears in print on , on Page A11 of the New York edition with the headline: Two Women Are Killed in a Knife Attack at a Train Station in Southern France. Order Reprints | Today’s Paper | Subscribe