Les Bleus qualified for the quarterfinals with the victory but were almost left with red faces after a late Samoa try left them hanging on to claim a third straight win in the tournament.
England awaits next weekend for France, which will have to improve its performance if it wants to top the pool.
Trailing 23-14 with the clock running down, Tonga launched one final attack with Zane Kapeli collecting a crossfield kick for its third try, converted by Latiume Fosita.
READ: France hold off spirited US for narrow win
Fortunately for the French there was barely time for a restart, but coach Jacques Brunel was unhappy with the display.
“We missed three or four chances and then we tightened up. There was tension, errors, we cannot manage the second half, especially at the start,” he said.
France, going into the match off the back of wins over Argentina, impressively, and the USA, less so, made a confident start and was 17-0 ahead in the first half.
Virimi Vakatawa and Alivereti Raka went over for tries for France, both converted by Romain Ntamack, who also kicked an early penalty.
But the Tonga fightback started just before the interval as Sonatane Takulua was judged to have grounded the ball over the line, getting up to make the conversion.
French concern increased early in the second half as Malietoa Hingano capitalized on hesitant defense to go over for a second Tonga try, with Takulua kicking the extras again.
Two penalties from Ntamack gave France breathing space, leading by nine points until Tonga’s last heroic effort yielded a third try as Kapeli took the opportunity.
View the latest Rugby World Cup news, feature stories, photos and videos on CNN.com.
Tonga coach Toutai Kefu was left to ponder what might have been an upset win over a Tier 1 nation.
“There was a period there when the game was in the balance. And the guys hung in and they hung in. You can’t question their effort,” he said.
All Black power
Earlier Sunday, two-time defending champion and tournament favorite New Zealand crushed Namibia 71-9, with 11 tries, topping Pool B from South Africa with one match remaining.
But it was a brave showing for the underdog Namibia, which only trailed 10-9 after 30 minutes until the All Blacks stepped up a gear.
New Zealand coach Steve Hansen was less than impressed by his side’s sloppy opening.
“The first half was pretty disappointing. We didn’t turn up with the attitude and Namibia made us pay for that. It’s a good lesson, isn’t it?
“Second half, there was pretty good stuff in it,” he added.
Namibia’s Welsh coach Phil Davies praised his side’s early contribution: “I’m very proud of the effort we put in. Particularly our ball retention and line breaks in the first half,” he said.
However, New Zealand’s play once it fully kicked into gear was impressive with Sevu Reece, Anton Lienert-Brown and Ben Smith all crossing for two tries apiece.
Angus Ta’ava, Joe Moody, Sam Whitelock, Jordie Barrett and TJ Perenara also went over, the latter rounding off the performance with a spectacular one-handed effort in the corner.
Stand-in fly half Barrett, singled out by Hansen for special praise, added eight conversions in a personal haul of 21 points.
Damian Stevens had kicked Namibia into an early 3-0 lead and added two further penalties in the closely contested early play.
Source : Cnn