Scotland progressed into the knockout phase of the World Cup for the first time courtesy of Italy's 16-0 defeat by Tonga.
Italy knew victory would see them win Group C ahead of Scotland because of their superior points difference.
But Tonga won through tries by Willie Manu, Daniel Foster and Peni Terepo.
Scotland beat Tonga and the USA, either side of a 30-30 draw against Italy, to finish top and set up a quarter-final against holders New Zealand on Friday.
The Azzurri enjoyed plenty of possession and territory throughout, but were unable to convert that pressure into tries.
They were held up agonisingly short of the Tongan line on several occasions as their already-eliminated opponents showed no intention of ending their campaign with a whimper in Halifax.
Tonga knew their participation in the tournament would be over after the Italian encounter, as Scotland's win over USA on Thursday meant they could not overhaul the unbeaten Bravehearts.
Neither side managed to put a point on the scoreboard until the final minute of a tight first half.
But the Pacific Islanders held a slender 2-0 lead at the break after winning a 40th-minute penalty in front of the Italian posts. Stand-off Samsoni Langi elected to kick at goal and booted the simplest of attempts to edge his team ahead.
Italy continued to press straight from the restart and centre James Tedesco showed electric pace to slide over the line, but was unable to ground the ball.
And the Azzuri fell further behind when Tonga scored the game's opening try after 47 minutes.
St Helens forward Manu scattered a host of Italian defenders to reach out for the line and, after the try was awarded by video referee Phil Bentham, Langi added the conversion.
Italy continued to pound the opposition line, but conceded again when scrum-half Foster darted in to finish a rare Tongan attack.
And Scotland, who watched the match from their hotel base in Manchester, knew their last-eight place was secure when Terepo crashed over in the dying moments.
Tonga: Mataitonga, Tupou, Hurrell, Fonua, Taufua, Langi, Foster, Kite, Politini, Moimoi, Ta'ai, W. Manu, Paea, Seluini.
Replacements: Vave for Moimoi (25), Terepo for Paea (37), Politini for Seluini (3).
Italy: A Minichiello, Mantellato, Tedesco, Guerra, Centrone, Falcone, Ghietti, Laffranchi, Parata, Vaughan, M Minichiello, Ciraldo, Riethmuller.
Replacements: Snowden for Laffranchi (23), Nasso for Parata (24), Santi for Vaughan (26).
Referee: Ben Thaler (England).