Scotland secured their place in the Rugby World Cup quarter-finals with a 36-33 win Samoa at St James' Park in Newcastle.
Greig Laidlaw kicked 19 points and clinched the win with Scotland's third try to go with scores from Tommy Seymour and John Hardie in the first half, as Scotland eventually edged an arm wrestle in the highest-scoring game of the tournament so far.
Win and Scotland knew they would be in the last eight ahead of Japan, but this was far from a cruise for Vern Cotter's men.
They only took the lead for the first time after 50 minutes and were regularly opened up by Samoa's elusive runners, relying on the boot of their captain Greig Laidlaw to punish Samoa's indiscipline in the second half.
Samoa's World Cup bit the dust against Japan last weekend, another low in what has been an disappointing tournament after plenty of hope.
Stephen Betham's side had nothing to play for but pride in potentially their coach's final game in charge. If that proves to be the case then they have sent him off in style, even if the result eluded them despite finishing with a bonus point try.
Tusi Pisi's penalty opened the scoring before Laidlaw quickly responded with three points of his own.
The Samoa fly-half though came up with the first try when he went over in the corner, grounding the ball with his fingertips with the score confirmed by the TMO. A superb touchline conversion from Pisi made it 10-3.
Tim Nanai-Williams has added so much to Samoa's attacking play, but off the restart he shot himself in the foot with a wild pass inside his 22, gratefully gobbled up by Tommy Seymour for the easiest try he'll ever score as Scotland drew level.
Rather than that blunder knocking Samoa off their stride, the Islanders burst into life off the restart.
Zak Taulafo's straight line split the Scottish defence wide open and after David Denton was penalised at the ruck, Fotuali'i wasted no time – taking a tap penalty and sending the ball wide for Ma'atulimanu Leiataua to crash over, mobbed by his celebrating team-mates after their fast start.
Oozing confidence through their midfield partnership of Rey Lee-Lo and George Pisi, Samoa found space time and again in Scotland's increasingly narrow defence.
A blindside attack saw Fotuali'i move the ball wide, with Lee-Lo taking the final pass to score Samoa's third try inside 20 minutes for a 20-13 lead.
Laidlaw's second penalty closed the gap but they were sent down to 14 men after the red mist descended on Ryan Wilson.
The flanker's stamp on Maurie Fa'asvalau was born out of frustration at having his leg held off the ball, but he had to be shown a card and referee Jaco Peyper settled on yellow.
Losing a unit from their pack couldn't stop Scotland's rolling maul crashing over though from short-range, with John Hardie racking up his second try in four Tests since his debut. Laidlaw's conversion made it 23-23.
Samoa thought they had a bonus-point try before the half was out, but George Pisi's pull on the arm of Laidlaw made the space for Taulafo to dive over the line. It was cynical from the Samoa centre, but how likely Laidlaw would have been to stop Taulafo anyway from that distance was worth debating.
Samoa had to settle for a third penalty from Tusi Pisi to make it 26-23 and they should have taken three more points with a penalty ten metres out before half-time. Fotuali'i, outstanding throughout the first half, instead opted to tap and the chance was lost.
Scotland had chances to counter through multiple rolling mauls at the start of the second half, turning down shots at goal, but after a succession of misfires Laidlaw opted for the posts to tie things up again at 26-26.
Another penalty from Laidlaw put Scotland ahead for the first time in the contest after 53 minutes but an attempt at a fifth strike fell wide, holding Scotland's lead at three points for the time being.
Samoa though were taking the brunt of a wave of penalties against them, with Laidlaw's next opportunity never far away.
A second straight miss though was uncharacteristic as Scotland failed to pull away, setting up a nervous finish.
Sean Lamont came off the bench to win his 100th cap as Scotland threw everything at Samoa's defence before Laidlaw found the breakthrough, darting down the blindside off a five-metre scrum and reaching out to ground the ball.
Samoa weren't done, striking back from close-range themselves through replacement hooker Motu Matu'u for their bonus point try with Patrick Fa'apale's conversion making it 33-36.
There was to be no fairytale though for Samoa as their final attack ended with a handling error – Scotland surviving to book their spot in the quarter-finals, also ensuring that Japan cannot get through regardless of their result against the USA on Sunday.
Man of the Match: For his points haul of 26 it has to go to Greig Laidlaw, although Kahn Fotuali'i and Rey Lee-Lo were both outstanding for Samoa.
Moment of the Match: Having missed two kicks Scotland had to score again to put them out of reach and Laidlaw's try by the posts came when it was needed most.
Villain of the Match: While appreciating Ryan Wilson's frustration at having his leg held, his stamp was pretty reckless and could easily have seen him sent off.
Tries: T Pisi, Leiataua, Lee-Lo, Matu'u
Cons: T Pisi, Fa'apale
Pens: T Pisi 3
Tries: Seymour, Hardie, Laidlaw
Cons: Laidlaw 3
Pens: Laidlaw 5
Yellow Card: Wilson
Scotland: 15 Stuart Hogg, 14 Tommy Seymour, 13 Mark Bennett, 12 Matt Scott, 11 Sean Maitland, 10 Finn Russell, 9 Greig Laidlaw (c), 8 David Denton, 7 John Hardie, 6 Ryan Wilson, 5 Jonny Gray, 4 Richie Gray, 3 WP Nel, 2 Ross Ford, 1 Alasdair Dickinson.
Replacements: 16 Fraser Brown, 17 Gordon Reid, 18 Jon Welsh, 19 Tim Swinson, 20 Josh Strauss, 21 Henry Pyrgos, 22 Peter Horne, 23 Sean Lamont.
Samoa: 15 Tim Nanai-Williams, 14 Paul Perez, 13 George Pisi, 12 Rey Lee-Lo, 11 Fa'atoina Autagavaia, 10 Tusi Pisi, 9 Kahn Fotuali'i (c), 8 Alafoti Faosiliva, 7 Jack Lam, 6 Maurie Faasavalu, 5 Kane Thompson, 4 Teofilo Paulo, 3 Census Johnston, 2 Ma'atulimanu Leiataua, 1 Sakari Taulafo.
Replacements: 16 Motu Matu'u, 17 Viliamu Afatia, 18 Anthony Perenise, 19 Faifili Levave, 20 Vavae Tuilagi, 21 Vavao Afemai, 22 Patrick Fa'apale, 23 Ken Pisi.
Referee: Jaco Peyper (South Africa)
Assistant Referees: JP Doyle (England), Marius Mitrea (Italy)
TMO: Ben Skeen (New Zealand)