Two French soldiers and a French hostage have been killed during a failed operation to free him in Somalia, the defence ministry says.
Commandos backed by helicopters reportedly swooped on the southern town of Bulo Marer during the night, targeting al-Shabab militants.
According to the defence ministry, the hostage was killed by his captors.
The raid in east Africa came hours after French troops intervened in the west African state of Mali.
The French military named the hostage as Denis Allex, who was kidnapped in Somalia in July 2009 along with a colleague, freed the following month.
France was "engaged in a merciless fight against terrorism wherever it is found", Defence Minister Jean-Yves Le Drian told reporters in Paris.
It seems likely that the operation was linked to the intervention in Mali, the BBC's Hugh Schofield reports from Paris.
The French government knew well the intervention would have dangerous implications for the nine French hostages being held across northern Africa, our correspondent says.
According to the French defence ministry, 17 militants were killed in the fighting in the town in the lower Shabelle region.
"Faced with the instransigence of the terrorists, who refused to negotiate for three and and half years and who were holding Denis Allex in inhumane conditions, an operation was planned and carried out," it said.
"During the assault, violent combat took place. Denis Allex was killed by his captors."
In a statement, al-Shabab reported a "fierce firefight" that lasted 45 minutes.
Giving no details of its own casualties, the group said it had killed "several" French soldiers and had captured an injured soldier.
The group said Mr Allex had not been killed in the raid, and instead was "safe and far from the location of the battle". It said an announcement about his fate would be made within two days.
Eyewitnesses in the town heard fighting during the night, then saw bodies this 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.
Of the other French hostages, at least six are being held by the al-Qaeda in the Islamic Maghreb group, AFP reports.
Mr 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.
On Friday, President Hollande announced that French forces were supporting an offensive by the Malian government to regain territory captured by Islamist militants in the north.
It was confirmed that French jets had made air strikes as Islamist rebels were forced out of the town of Konna.
Mr Hollande said Islamists had been trying to turn Mali into a "terrorist" state and the French intervention complied with international law and had been agreed with Malian interim President Dioncounda Traore.