France limped into the World Cup quarter-finals despite losing to Tonga in one of the biggest shocks in the history of the tournament.
France took a 6-3 lead through two Dimitri Yachvili penalties before Tonga went ahead courtesy of Sukanaivalu Hufanga's converted try.
A Kurt Morath penalty made it 13-6, Yachvili cutting the margin with his third penalty soon after the break.
Morath added two more kicks but Vincent Clerc's late try earned a bonus point.
Morath also missed three second-half penalties and a drop-goal, while Tonga bombed several tries as they dominated for long periods of the match.
But the losing bonus point means France have qualified for the last eight anyway.
Had they failed to finish within seven points, Canada could still theoretically have pipped them to second place in the group with a bonus-point win over New Zealand, but Clerc's late intervention removes that remotest of possibilities.
In the end Tonga fell well short of the big win that would have taken them into the last eight at France's expense, and they will be cursing their 25-20 defeat by Canada earlier in the tournament.
That meant a simple victory over France would not be enough to send them into the last eight and that a bonus point was also required.
And even though France looked bereft of both punch and ideas, it always seemed likely they would do just enough to ensure they would maintain their record of always reaching the knock-out stages at World Cups.
Tonga were massively physical both with and without the ball, and players from both sides were soon leaving the field bloodied and bruised in Wellington.
France led 6-3 after 25 minutes through two Yachvili penalties to one from Morath but Tonga then took the lead with a superb try.
Taniela Moa made a superb initial break to get the French backpedalling and when the ball was recycled Morath cross-kicked for the lurking Hufanga.
The winger brushed off covering France flanker Julien Bonnaire, who made a very poor attempt at a tackle, and powered over to give Tonga the lead.
Morath converted and, after William Servat had a try ruled out for a double movement, the fly-half added a penalty to give Tonga a 13-6 lead at half-time.
A Yachvili penalty for France cut the deficit to four points with 30 minutes to play but rather than Les Bleus taking control, it was Tonga who dominated the rest of the match.
Time and again the Pacific Islanders poured forward in attack but a combination of last-ditch France defence, and poor option-taking by Tonga, ensured they could not cross the French line.
However, two more Morath penalties meant that by the time France finally mounted a sustained attack in the dying moments of the game, Tonga were already guaranteed victory.
The match ended in bizarre circumstances, as France turned down a kick at goal which would have ensured they would secure the losing bonus point that would take them into the last eight.
Instead they opted for a scrum and when they moved the ball wide, Clerc dived over to score in the corner.
France at least progress to the knockout stages but the ecstatic reaction of the Tongans at the final whistle underlined that they had pulled off one of the biggest wins in the history of the game.
France: Medard; Clerc, Rougerie, Mermoz, Palisson; Parra, Yachvili; Poux, Servat, Ducalcon, Pape, Nallet, Dusautoir, Bonnaire, Lakafia.
Replacements: Estebanez for Rougerie (58), Heymans for Palisson (75), Trinh-Duc for Parra (58), Barcella for Poux (6), Szarzewski for Servat (49), Pierre for Pape (66).
Not Used: Harinordoquy.
Sin Bin: Estebanez (65).
Tonga: Lilo; Iongi, Piutau, Ma'ilei, Hufanga; Morath, Moa; Tonga'uiha, Lutui, Pulu, Lokotui, Hehea, Kalamafoni, Maka, Ma'afu.
Replacements: Fatafehi for Ma'ilei (61), Taumalolo for Tonga'uiha (47), Aulika for Pulu (42), Tuineau for Hehea (57), Vahafolau for Maka (10).
Not Used: Taukafa, Fisilau.
Sin Bin: Hufanga (38).
Ref: Steve Walsh (Australia).