
Samoa scored four tries to Tonga's three but missed three of four conversions, falling 20-18 after Addin Fonua-Blake's 72nd-minute try.
The victory at CommBank Stadium, watched by 29,411 people, kept Tonga unbeaten through the group stage and secured a semi-final against New Zealand.
Tonga coach Kristian Woolf said, "This group can do anything."
"We left four tries out there - two in the second half - and we've got plenty of improvement left in us."
Tonga will play New Zealand in Newcastle on Saturday, their first World Cup meeting since 2017, when Jason Taumalolo-led defections to Pacific nations shaped the tournament.
Samoa coach Ben Gardiner said, "That's one of those things that happens in rugby league."
"But I'm very happy with the level of performance, the intensity and the way we went about the business."
Samoa's Chanel Harris-Tavita missed a conversion chance, then left midway through the second half clutching his hamstring.
He appears unlikely to face Australia in the other semi-final.
Substitute Ronald Volkman scored and converted to put Samoa ahead late, but Fonua-Blake's powerful run through the middle secured Tonga's win.
The semi-finals are New Zealand v Tonga on Saturday November 7 at 8.05pm, and Australia v Samoa on Sunday November 8 at 8.05pm.
