Denis Allex was filmed by his captors
Denis Allex, a French soldier held hostage in Somalia since 2009, was killed during a raid on Friday night by French troops trying to rescue him, the French defense ministry said on Saturday.
Two other French soldiers and 17 Somalian fighters were killed in the fighting, the ministry said in a statement, reports Reuters.
"Faced with the intransigence of the terrorists, who refused to negotiate for three and half years and who were holding Denis Allex in inhumane conditions, an operation was planned and carried out," said the ministry.
"During the assault, violent combat took place. Denis Allex was killed by his captors."
Eyewitnesses in the town in the lower Shabelle region heard fighting during the night, then saw bodies Saturday morning.
Up to four helicopters were involved in the operation, they said.
Mohamed Ali, a resident of Bulo Marer, told AP news agency by phone: "We heard a series of explosions followed by gunfire just seconds after a helicopter flew over the town.
"We don't know exactly what happened but the place was an al-Shabab base and checkpoint."
Another resident of the town, Idris Youssouf, told AFP that details were sketchy because the attack had happened at night.
"But this morning we saw several corpses including that of a white man," he added.
He said three civilians had also died in the fighting.
According to the French defence ministry, 17 militants were killed in the fighting.
Of the other French hostages, at least six are being held by the al-Qaeda in the Islamic Maghreb group, AFP reports.
Allex, reportedly an agent of France's DGSE intelligence service, appeared in a video in June 2010, appealing to France to drop its support for the Somali government.
He last appeared in another video in October, looking gaunt and calling on French President Francois Hollande to work for his release.
Somalia has not had an effective central government for more than two decades.
France has a large military base in neighbouring Djibouti, including army, marine and air force units.