A gun-wielding extremist unleashed bloodshed in a quiet corner of southern France, killing three people as he hijacked a car, opened fire on police and took hostages in a supermarket.

The 26-year-old attacker, who called himself a “soldier of Islamic State” when he entered the supermarket, was killed as police stormed the store with the help of an officer who had switched places with a hostage and suffered life-threatening wounds — one of 16 people injured.

The Islamic State group claimed responsibility for the rampage near Carcassonne and the town of Trebes. It was the deadliest attack in France since Emmanuel Macron became president last year.

The officer who offered to be swapped for a female hostage was identified as Arnaud Beltrame.

He managed to surreptitiously leave his phone on so that police outside could hear what was going on inside the supermarket — and crucially, decide when to storm it.

“He saved lives,” Mr Macron said.

He said investigators will now focus on establishing how the gunman, identified as Redouane Lakdim, obtained his weapon, and how he became radicalised.

He was known to police for petty crime and drug-dealing and was under surveillance — but not suspected of extremist links.

The hours-long drama began when the attacker hijacked a car near the medieval city of Carcassonne on Friday morning, killing one person in the car and injuring the other, according to French interior minister Gerard Collomb.

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

The police were wearing athletic clothes with police insignia.

One officer was shot in the shoulder but the injury was not serious, Mr Lefebvre said.

France terror attack
(PA graphic)

Lakdim then went to a Super U supermarket in the nearby small town of Trebes, 60 miles south east of Toulouse, shooting and killing two people in the market and taking an unknown number of people hostage.

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

Police were able to evacuate some shoppers at the supermarket.

Mr Collomb said two other officers were wounded during the assault.

Police attend the incident in Trebes (La Depeche Du Midi via AP)
Police attend the incident in Trebes (La Depeche Du Midi via AP)

“He acted alone, there was no-one else but him,” Mr Collomb said, speaking from Trebes.

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 minister added.

He said Lakdim was a petty criminal and small-time drug dealer who had been under police surveillance, but it was not clear to authorities that he was a committed radical.

“It was more of a petty criminal who at a certain moment decided to act,” Mr Collomb said.

A customer in the supermarket described the assailant as a “very agitated man shouting several times ‘Allahu akbar!'”

Christian Guibbert told reporters “we heard an explosion, well, several explosions. So 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 one”.

Mr Guibbert said he had sought shelter with his wife, sister-in-law and other customers in the butcher’s refrigerator.

Then he went back into the supermarket’s main room and walked towards the assailant, calling police and describing the situation.

He said the suspect “ran after me”.

Mr Guibbert escaped out of an emergency market door as elite police forces arrived to storm the building.

A police vehicle parked on a crossroad in Trebes (BFM TV via AP)
A police vehicle parked on a crossroad in Trebes (BFM TV via AP)

The IS-linked Aamaq news agency said the attacker was responding to the group’s calls to target countries in the US-led coalition carrying out air strikes against IS militants in Syria and Iraq since 2014.

France has been repeatedly targeted because of its participation in the air strikes.

Counter-terrorism investigators took over the probe into Friday’s rampage.

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

While France has not seen an attack in several months “the threat remains high”, Mr Macron said, describing ongoing risks from “several individuals who radicalised themselves”.

The attack on Friday occurred in a normally quiet part of France, where the main tourist attraction is the treasured old city of Carcassonne, its medieval walls and its summertime festivals.

French police officers cordon off the area (Emilio Morenatti/AP)
French police officers cordon off the area (Emilio Morenatti/AP)

The attack poses a new challenge to Mr Macron’s leadership as he faces nationwide strikes and criticism of his reforms, which include a tough new counter-terrorism law that gives police extra powers to conduct searches and hold people under house arrest.

Mr Macron rushed back from an EU summit in Brussels to the crisis centre in Paris that was overseeing the investigation into the attack.

Standing next to Mr Macron in Brussels, German Chancellor Angela Merkel expressed her sympathy with those affected by the hostage-taking.

“When it comes to terrorist threats, we stand by France,” she said.