Tonga registered the first win of their World Cup campaign, seeing off a spirited Japan 31-18 in Whangarei.
Viliami Ma'afu and Tukulua Lokotui scored tries for Tonga, but Japan responded on each occasion to stay within five points at the break.
Winger Fetu'u Vainikolo extended the lead, before Alisi Tupuailai's score hinted at a Japan comeback.
Lokotui picked up Tonga's second yellow card of the match late on but his team held on comfortably in the end.
The result confirms Japan's exit from the competition but Tonga's hopes of reaching the knockout stages, while slim, remain alive.
The Pacific Islanders require New Zealand to convincingly beat win France on Saturday before they themselves score four tries in inflicting a second defeat on Marc Lievremont's men in their final group game.
Their performance against Japan gave little indication that such an upset might be on the cards, but Tonga's physicality and fly-half Kurt Morath's superior place kicking proved enough to wrap up the victory despite ending the contest camped on their own line.
After only five minutes, number eight Ma'afu was held up over the line when he barged his way over after picking up at the back of the scrum.
While prop Kensuke Hatakeyama burrowed over with a short-range effort of his own, his coach and former All Black John Kirwan will have been dismayed by the manner Japan slipped back behind straight off the restart.
The ball squirted out of the side of a ruck as Japan attempted to gather possession and second row Lokotui charged into the corner from Taufa'ao Filise suspiciously forward-looking pass.
Flanker Michael Leitch crossed from Shaun Webb's inside ball, but the conversion was missed and Morath slotted three penalties to ease Tonga more than a converted score clear in the second half.
Vainikolo's try, from Siale Piutau's imaginative offload, seemed to seal the result before indiscipiline briefly threatened to derail Tonga.
Replacement prop Halani Aulika was sinbinned for his team's persistent infringements and Tupuailai powered his way through Tonga's depleted defence shortly after.
But James Arlidge missed the conversion and the Tonga front row, enjoying a significant size advantage over their opposite numbers, forced another penalty from which Morath landed the final points of the match with his sixth successful kicks from seven attempts.
Japan: Shaun Webb, Kosuke Endo, Alisi Tupuailai, Ryan Nicholas, Hirotoki Onozawa, James Arlidge, Fumiaki Tanaka; Takashi Kikutani (captain), Michael Leitch, Itaru Taniguchi, Toshizumi Kitagawa, Luke Thompson, Kensuke Hatakeyama, Shota Horie, Hisateru Hirashima. Replacements: Yusuke Aoki, Nozomu Fujita, Hitoshi Ono, Sione Talikavili Vatuvei, Atsushi Hiwasa, Takehisa Usuzuki, Murray Williams.
Tonga: Vungakoto Lilo, Fetu'u Vainikolo, Siale Piutau, Alipate Fatafehi, Sukanaivalu Hufanga, Kurt Morath, Taniela Moa; Soane Tonga'uiha, Aleki Lutui (captain), Taufa'ao Filise, Tukulua Lokotui, Paino Hehea, Sione Kalamafoni, Sione Vaiomo'unga, Viliami Ma'afu. Replacements: Aloisio Ma'asi, Alisona Taumalolo, Halani Aulika, Joseph Tu'ineau, Samiu Vahafolau, Samisoni Fisilau, Andrew Ma'ilei.