The Irish scored 3 tries to 1 and after re-taking the lead just before half-time, didn't look back. Similalry, New Zealand were only 13-11 ahead at half-time but pulled way in the second half, with Ben Franks scoring the final, vital try that kept them out of reach.
South Africa and Australia will play for the 3rd place spot at Hughenden in the earlier kick-off (1:45pm).
Wales came from behind to beat France at Raeburn Place to book themselves a fine 5th/6th play-off match against England, who beat Argentina comfortably in the end down at Netherdale.
Scotland left it until deep into injury time at Netherdale before they pulled their game out the bag. With the last kick of the game, Brian Archibald kicked the penalty that gave Scotland the last-gasp win. Indeed it was the first time they d been in the lead all game - Tonga had taken the lead in the 10th minute and held on to it thereafter.
Scotland, then, go into Sunday s 9th/10th play-off against Italy, who beat Russia at Raeburn Place. The unlucky Tongans will play Russia for the 11/12th play-off. It could have been so different, and the Scots will sigh a mighty sigh of relief.
Andrew Finn (Dolphin); Richard Lane (UCC), John Hearty (Blackrock College), Glen Telford (Dungannon), Paul McKenzie (Loughborough University); Gareth Steenson (Queens University), Tomas O'Leary (Cork Constitution);John Wickham (Clontarf), Denis Fogarty (Cork Constitution), Declan Fitzpatrick (Belfast Harlequins); David Gannon captain (Blackrock College), Shane O'Connor (Cork Constitution), Brendan O'Connor (Cork Constitution), David O'Brien (Old Belvedere), Jamie Heaslip (Dublin University).
Replacements: 16 Conor Geoghegan (UCD), 17 Keith Doyle (UCD), 18 Neil McComb (Dundee HSFP), 19 Oisin Hennessy (Dungannon), 20 Robbie Shaw (Wasps), 21 Michael Glancy (Loughborough University), 22 Breiffne O'Donnell (UL Bohemians).
15 Drew Mitchell captain; 14 Henari Veratau, 13 Josh Graham, 12 Chris Siale, 11 Cameron Shepherd, 10 Daniel Halangahu, 9 Josh Valentine, 8 Mitch Chapman, 7 Lei Tomiki, 6 Rocky Elsom, 5 Alex Kanaar, 4 Simon Hockings, 3 Rodney Blake, 2 Steve Moore, 1 Hermon Hunt.
Replacements: 16 Luke Holmes, 17 Greg Holmes, 18 Richard Brown, 19 Josh Fuimaono, 20 Luke Burgess, 21 Adam Ashley Cooper, 22 Chris Lyons.
Australia 13, Ireland 26; Wales 29, France 21; England 39, Argentina 13; Scotland 18, Tonga 17; New Zealand 26, South Africa 11; Italy 33, Russia 20