The French policeman who swapped himself for a hostage in Friday's attack has died of his wounds, Interior Minister Gerard Collomb said on Saturday.

"Lieutenant-Colonel Arnaud Beltrame has passed away. He died for his country. France will never forget his heroism," the minister wrote on his Twitter account.

Three other people were also killed and 16 were wounded after the 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.

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

After the attack, President Emmanuel Macron said the officer who took the place of the hostage was "fighting for his life", but he later succumbed to his wounds.

Quelle tristesse d'apprendre la mort du lieutenant-colonel Arnaud Beltrame ! Son acte héroïque fait notre admiration et il restera à tout jamais dans nos https://t.co/2Z13VGw436 pense à sa famille et à ses camarades gendarmes qui ce matin le pleurent. #Trèbes #Carcassonne pic.twitter.com/ADsilWkejI — Manuel Valls (@manuelvalls) March 24, 2018

Macron said investigators will focus on establishing how the gunman, identified by prosecutors as Redouane Lakdim, got his weapon and "how he became radicalised".

On Friday night, authorities searched a vehicle and a building in central Carcassonne. Lakdim was known to police for petty crime and drug dealing.

But he was also under surveillance and since 2014 was on the so-called "Fiche S" list, a government register of individuals suspected of being radicalised but who have not performed acts of violence.

Despite this, Paris prosecutor Francois Molins said there was "no warning sign" that Lakdim would carry out an attack.

A woman close to Lakdim was taken into custody over alleged links with a "terrorist enterprise", Molins said. He did not identify her.

Four-hour drama

The attack began at 10:13am when Lakdim hijacked a car near Carcassonne, killing one person in the car and wounding the other, the prosecutor said.

Lakdim then fired six shots at police officers who were on their way back from jogging near Carcassonne, said Yves Lefebvre, secretary-general of SGP Police-FO police union.

The police were wearing athletic clothes with police insignia. One officer was hit in the shoulder, but the injury was not serious, Lefebvre said.

Lakdim then went to a Super U supermarket in nearby Trebes, 100km southeast of Toulouse, shooting and killing two people in the market and taking an unknown number of hostages.

Special police units converged on the scene while authorities blocked roads and urged residents to stay away.

He shouted "Allahu akbar! (God is great)" and said he was a "soldier of the Islamic State (ISIL)" as he entered the Super U, where about 50 people were inside, Molins said.

"We heard an explosion - well, several explosions," shopper Christian Guibbert told reporters. "I went to see what was happening and I saw a man lying on the floor and another person, very agitated, who had a gun in one hand and a knife in the other."

During the standoff, Lakdim requested the release of Salah Abdeslam, the sole surviving assailant of the November 13, 2015, attacks in Paris that left 130 people dead.

The interior minister suggested, however, that Abdeslam's release wasn't a key motive for the attack.

The ISIL-linked Aamaq website said the attacker was responding to the group's calls to target countries in the US-led coalition carrying out air raids against ISIL fighters in Syria and Iraq since 2014.

France has been repeatedly targeted because of its participation.

France has been on high alert since a series of attacks in 2015 and 2016 that killed more than 200 people.