Three people have been killed and 16 were wounded after a gunman held up a car, opened fire on police and then took hostages in a supermarket in southern France.

Police later on Friday stormed the supermarket in the small town of Trebes and shot dead the attacker.

Officials confirmed the death of the gunman on Twitter.

#Trèbes : fin des opérations. Le terroriste a été abattu. 3 morts sont annoncés dont plusieurs blessés. — SD POLICE MUNICIPALE (@SDPM_MICHEL) March 23, 2018

French officials said the gunman claimed allegiance to the Islamic State of Iraq and the Levant (ISIL, also known as ISIS) group.

In a televised address, President Emmanuel Macron said a police officer who took the place of a female hostage is "fighting for his life". He said France had suffered "an Islamist terrorist attack".

🔴[OPERATION POLICE]🔴

⚠️ Opération en cours secteur Super U Trèbes.

Secteur interdit ⚠️

Merci de faciliter l'accès aux forces de l'ordre. — Préfecture de l'Aude (@Prefet11) March 23, 2018

Three separate incidents

First, the attacker held up a car just before 10am in the nearby village of Carcassonne, killing one person and leaving another wounded, according to local media reports.

Then, he fired at police officers who were on their way back from jogging, according to Yves Lefebvre, secretary-general of SGP Police-FO police union.

One soldier was slightly injured after being shot in the shoulder, Lefebvre said.

Then the gunman drove that car to a Super U supermarket in the nearby small town of Trebes, about 100km southeast of Toulouse, where he entered the supermarket.

He shot two people dead after he entered the supermarket.

The attacker was able to take a police officer hostage after all other people were able to escape the shop.

The police officer swapped himself with a civilian, and was subsequently severely injured in the assault, Interior Minister Gerard Collomb said in a statement.

National and local media in France reported that the man claimed that he carried out the attack in the name of ISIL.

According to several sources, the hostage-taker demanded the release of Salah Abdeslam, the only surviving member of the November 2015 attacks in Paris, in which 130 civilians and seven attackers were killed.

Julien Theron, a political analyst at Sciences Po, told Al Jazeera the attacker spoke about his connection to ISIL.

"The man claimed to belong to ISIS, but so far there has been no claim from ISIS itself," Theron said.

"He spoke about defending his brothers in Syria and also claiming to free Salah Abdelsalam, one of the attackers of the Bataclan attacks."

Local media also reported the mother and sister of the unidentified suspect came to the supermarket to try and persuade him to give up.

Police also indicated they would try to take the gunman alive so he could be questioned and tried in court.