Lieutenant-Colonel Arnaud Beltrame, 45, was among a group of officers who rushed to the scene in the town of Trebes in southwest France Friday after the attacker, who claimed allegiance to the Islamic State group, stormed a supermarket and fired at shoppers and staff.
Beltrane 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. He died for his country. France will never forget his heroism," Interior Minister Gerard Collomb said on his Twitter account.
President Emmanuel Macron earlier paid tribute to the bravery of the police officer.
"He saved lives and honoured his colleagues and his country", Macron said. He also said that Beltrame he"fell as a hero" and showed "exceptional courage".
With the death of the officer, the assailant, identified as 25-year-old Radouane Lakdim, killed a total of four people in France's first major jihadist attack since October.
"Our country has suffered an Islamist terrorist attack," Macron said in a televised address following the rampage in the medieval town of Carcassonne and nearby Trebes.
The Islamic State group claimed the attack was in response to its call to target Western enemies -- as is customary when the assailant has pledged allegiance to the jihadists.
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 watchlist for his radicalisation and links to the Salafist movement," 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, Molins said.
Lakdim started his rampage in Carcassonne at around 10:30 am (0930 GMT), hijacking a car and shooting the two people inside, Molins said. The passenger was killed, and the driver remains in a critical condition.
Lakdim then shot and wounded a police officer who was out 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," Molins said.
He further 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 though some people managed to escape, several remained inside.
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, Collomb said.
When special forces heard shots they stormed the store, killing the gunman and recovering 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.
Tough questions for government
Trebes, a sleepy town of 5,000 people along the Canal du Midi, was on lockdown throughout Friday as helicopters swirled overhead 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 Macron's government as to how he slipped through the net.
"We had monitored him and did not think he had been radicalised," Interior Minister 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.
Friday's violence took place in a part of France still scarred by a killing spree in 2012 in the city of Toulouse and nearby Montauban where another jihadist, Mohamed Merah, shot dead seven people including three Jewish schoolchildren.
That assault marked the first of several big Islamist attacks in France since 2015, including the massacre at the satirical newspaper Charlie Hebdo, the November 2015 attacks that killed 130 in Paris, and a summer 2016 truck attack during Bastille Day festivities in Nice.
The most recent assault came in October when a Tunisian man stabbed to death two women at Marseille's railway station, shouting "Allahu Akbar".
A state of emergency put in place just after the 2015 Paris attacks was lifted last October when Macron's centrist government passed a new law boosting the powers of security forces.