Kristian Woolf's side kept their undefeated group-stage record intact after Cronulla prop Addin Fonua-Blake crossed in the 72nd minute to snatch victory at CommBank Stadium in front of 29,411.
Tonga will face the Kiwis in Newcastle on Saturday in what will be the first World Cup meeting between the two nations since the 2017 tournament, which was characterised by the Jason Taumalolo-led defections to the Pacific nations.
Taumalolo was impressive for Tonga on Sunday night but Samoa gave their Polynesian brethren a major leg-up by missing three of their four conversion attempts.
"That's one of those things that happens in rugby league," said Samoa coach Ben Gardiner.
"But I'm very happy with the level of performance, the intensity and the way we went about our business."
Samoa outscored Tonga four tries to three, but Chanel Harris-Tavita and Ronald Volkman could only land one goal between them.
Harris-Tavita came off midway through the second half, clutching at a hamstring after missing a shot at goal and now appears unlikely to line up for Samoa against Australia in the other semi-final.
It looked as if things were going to be straightforward for Tonga, who had the upper hand for much of the first half but only had an 8-4 lead to show for it.
Wingers Dallin Watene-Zelezniak and Jojo Fifita both crossed but had tries chalked off on review before Sydney Roosters star Rob Toia continued his incredible run of form to score Tonga's opener in the 26th minute.
Haumole Olakau'atu ran over the top of Samoan five-eighth Jarome Luai before getting the ball away to Toia, who raced home from 50m out and dotted down under the sticks.
Halfback Isaiya Katoa converted then added a penalty after Jermaine McEwen was ruled to have interfered at the ruck.
But late in the first half, Luai put up a fifth-tackle kick that was batted back to Stephen Crichton, who flicked a late offload away for Brian To'o to score.
Fifita hit back for Tonga soon into the second half before Harris-Tavita flicked another Luai kick out to To'o to keep Samoa in the game.
Harris-Tavita struck the upright with his attempt then winced as he grabbed at his left hamstring.
Volkman was thrown into the action and the substitute No.6 was soon called upon to take a conversion which offered the chance to tie the game up.
It came after Luai and Sua Fa'alogo combined down the left before Hamiso Tabuai-Fidow finished the move.
Volkman was unable to add the extra points but pushed his side ahead when he pinballed through some tired Tonga defenders to score. He then converted his own try, with less than 12 minutes left.
But just as Samoa looked set to hang on, Fonua-Blake rampaged through the middle of the defence to snatch victory for Tonga.
"This group can do anything," Woolf said.
"We left four tries out there - two in the second half - and we've got plenty of improvement left in us.
"We keep heading on the right track but they (this team) can do anything."
WORLD CUP SEMI-FINALS
Semi-final 1: New Zealand v Tonga, Saturday November 7, 8.05pm
Semi-final 2: Australia v Samoa, Sunday November 8, 8.05pm