Tonga avoided finishing bottom of Pool C at the Rugby World Cup after overcoming the United States 31-19 on Sunday.
With both teams already eliminated, Tonga bowed out on a winning note by scoring four tries to USA's three in Higashiosaka.
Tonga trailed USA 12-7 at half-time after substitute Mike Te'o had grabbed a brace shortly after coming on.
But Tonga rallied to snap a run of five consecutive losses, which was their joint-worst streak at a World Cup.
Tonga started brightly and opened the scoring in the 17th minute thanks to Siegfried Fisiihoi, who bundled himself over after some desperate USA defending had initially held up the Tongans – with Sonatane Takulua adding the extras.
However, Tonga's 7-0 lead was short-lived as USA responded in brilliant fashion four minutes later.
USA sliced Tonga open – quick hands finding Te'o, who was too slick for his opponents on the wing and AJ MacGinty nailed the conversion to level proceedings.
Te'o was at it again in the 26th minute as USA turned the match on its head. The wing found himself in acres of space to stroll in, though MacGinty was unable to convert.
Tonga trailed 12-7 at the break after a golden opportunity went begging – Fisiihoi broke the lines but Ruben de Haas reached in for a tackle and broke the ball loose with five minutes remaining.
It was a Tonga onslaught to start the second half as they looked to strike back, and they reduced the deficit via Takulua's 51st-minute penalty.
Tonga regained the lead as the hour mark approached as Telusa Veainu's kick forward, with no one ahead, bounced favourably and allowed Mali Hingano to eventually sprint clear under the sticks.
After Takulua successfully converted, the tiring Americans conceded again four minutes later as retiring captain Siale Piutau weaved his way past three opponents to stretch Tonga's advantage to 24-12.
Tony Lamborn's late try set up a grand-stand finish but Veainu's five-pointer after the siren made sure of Tonga's first victory of this year's tournament.
Tonga send Piutau out a winner
In his final international match, 34-year-old Piutau scored a try and celebrated a victory in a dream Tonga farewell.
Te'o double not enough for USA
A pair of first-half tries from Te'o had USA dreaming against Tonga. However, his efforts were not enough as the United States matched their worst run in World Cup games – 10 straight defeats.
Both teams are heading home after a spirited effort at the showpiece tournament, with England and France qualifying from Pool C.