Police later stormed the supermarket in the small town of Trebes and the attacker was killed, Interior Minister Gerard Collomb told reporters at the scene.
The 26-year old attacker from the nearby city of Carcassonne, named as Redouane Lakdim, was known to authorities as a petty criminal but was not considered an militant threat, Collomb said, adding that he was believed to have acted alone.
More than 240 people have been killed in France in attacks since 2015 by assailants who pledged allegiance to Islamic State or were inspired by the group.
Islamic State claimed responsibility for Friday's attack but offered no details. The last lethal attack in France was in October 2017 when a Tunisian-born man stabbed two young women to death in Marseille before he was shot dead by soldiers.
Islamic State also claimed responsibility for that attack.
"Every day we detect facts and foil new attacks. Alas, this one struck without us being able to counter it," Collomb said.
Lakdim first killed one person with a bullet in the head while stealing a car in Carcassonne, which is one of France's top tourist attractions.
He then shot at four police officers who were jogging before taking hostages at the supermarket in Trebes, about 8 km to the east, where two people died.
"We had monitored him and thought there was no radicalisation," Collomb said. "He was known for possession of drugs. We couldn't have said that he was a radical that would carry out an attack."
Five people were wounded in the attacks, including three seriously. Lakdim shot one police officer in the shoulder in Carcassonne, a walled hill top city which is a UNESCO World Heritage site.
Speaking in Brussels, President Emmanuel Macron said the incident appeared to be a terrorist attack. He then headed back to Paris, where he was filmed chairing a crisis meeting with ministers and security officials.
Witnesses said about 10 people in the supermarket found refuge in its cold storage room.
A lieutenant-colonel swapped himself in exchange for one of the hostages, Collomb said, adding that the 45-year-old had been seriously wounded.
One supermarket worker said some shoppers had escaped from the building after the gunman shouted "God is greatest" in Arabic.
"I was in my department when I heard gunshots. I went to the area of the gunshots and came face to face with the person," said the employee, who gave his name only as Francois.
BFM TV reported that he claimed allegiance to Islamic State.
Collomb said the man had demanded the release of Salah Abdeslam —the prime surviving suspect in the Islamic State attacks that killed 130 people in Paris in 2015.
Abdeslam, a French citizen born and raised in Brussels, went on trial in Belgium last month.
He is accused of ‘attempted murder in a terrorist context’ over a Brussels shootout in March 2016, four months after he fled Paris on the night of the carnage during which his brother was among the suicide bombers.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ