A French policeman who was shot and stabbed after swapping himself for a hostage in a rampage and siege President Emmanuel Macron called "an Islamist terrorist attack" died of his wounds on Saturday, becoming the gunman's fourth victim.
Lieutenant-Colonel Arnaud Beltrame, 45, was among a group of officers who rushed to the scene in the town of Trebes in southwest France on Friday after the attacker, who claimed allegiance to ISIL, stormed a supermarket and fired at shoppers and staff.
Col Beltrame offered to take the place of a woman the gunman had taken hostage and was shot and badly wounded before anti-terror police moved in to kill the attacker and end the siege.
"Lieutenant-Colonel Arnaud Beltrame has passed away," Interior Minister Gerard Collomb said on his Twitter account. "He died for his country. France will never forget his heroism." Interior Minister Gerard Collomb said on his Twitter account.
Mr Macron earlier paid tribute to the bravery of the police officer.
"He saved lives and honoured his colleagues and his country," Mr Macron said.
The assailant, identified as 25-year-old Radouane Lakdim, killed another three people in France's first major militant attack since October.
"Our country has suffered an Islamist terrorist attack," Mr Macron said in a televised address following the rampage in the medieval town of Carcassonne and nearby Trebes.
ISIL claimed the attack was in response to its call to target western enemies - as is customary when the assailant has pledged allegiance to the terrorist group.
The shootings come as France remains on high alert following a string of deadly attacks that have killed more than 240 people since 2015.
Top anti-terror prosecutor Francois Molins said the gunman had convictions for carrying a banned weapon and for drug use.
"He had been on a watch list for his radicalisation and links to the Salafist movement," Mr Molins told reporters in Carcassonne, adding that Lakdim had been tracked for his online contacts with extremists.
Security sources said Lakdim was born in Taza in northern Morocco and held French nationality. His partner, who lived with him in Carcassonne, has been detained, Mr Molins said.
Lakdim started his rampage in Carcassonne at abut 10.30am (09.30GMT), hijacking a car and shooting the two people inside, Mr Molins said. The passenger was killed, and the driver remains in a critical condition.
Lakdim then shot and wounded a police officer who was jogging with colleagues before driving to nearby Trebes where he burst into the Super U supermarket.
"The attacker entered the store shouting "Allahu Akbar" (God is greatest) and saying he was a soldier of the Islamic State, ready to die for Syria," Mr Molins said.
He demanded "the release of his brothers" from prison before shooting a supermarket customer and an employee dead.
"I was five metres away from him," the store's security guard said, speaking on condition of anonymity.
"He shot at me twice." Luckily for the security guard, "he shot badly".
About 50 people were in the supermarket at the time, and although some people managed to escape, several remained inside.
Col Beltrame offered to take the place of a woman Lakdim was using as a human shield while his colleagues negotiated with the gunman, the interior minister said.
The officer "left his telephone on the table" to allow police who had surrounded the building to listen in, Mr Collomb said.
When special forces heard shots, they stormed the store killing the gunman and recovering Col Beltrame, who had been seriously wounded.
He was shot twice and stabbed several times by the attacker, a source close to the investigation told AFP.
Trebes, a town of 5,000 people along the Canal du Midi, was on lockdown throughout Friday as helicopters attended the scene and heavily armed and masked police carried out a massive operation in Lakdim's neighbourhood.
The fact that Lakdim had been monitored as a potential extremist will raise difficult questions for the French government.
"We had monitored him and did not think he had been radicalised," Mr Collomb said after flying to the scene.
"He was already under surveillance when he suddenly decided to act."
In Paris, the Eiffel Tower dimmed its lights at midnight in a mark of respect for the victims and a minute's silence was held at the Stade de France before a football match between France and Colombia.