Scotland booked their place in the quarter-finals of the World Cup after winning a pulsating game against Samoa in Newcastle.
Captain Greig Laidlaw starred with a try and 21 points with the boot for a personal best 26 points in a Test as Scotland won 33-36 at St James' Park.
First-half tries from Tommy Seymour and John Hardie kept the Scots in the game as Samoa took a 26-23 lead at the break.
Three tries in the opening 20 minutes from Tusi Pisi, Ma'atulimanu Leiataua and Rey Lee-Lo shocked Vern Cotter's team, who stayed in the game thanks to Laidlaw's accurate boot.
Stand-off Pisi kicked three penalties and a conversion, but ill-discipline cost the Pacific Islanders, who conceded far too many penalties, allowing the Scots to chip away at the deficit.
A late try from substitute Motu Matu'u and conversion by Patrick Fa'apale was not enough in the end.
What was tipped to be a tight contest before kick-off turned into a helter-skelter affair.
Scotland were the architects of their own downfall as three sloppy restarts inside the opening quarter cost them 20 points.
A penalty apiece after ten minutes from Laidlaw and Tusi Pisi preceded the next 11 minutes of madness.
Samoa reclaimed the their second restart and flyhalf Tusi Pisi surged into the Scots' 22m, Jack Lam set-up a ruck, Samoa recycled quick ball to Census Johnston, who threw a dummy and put his flyhalf into a gap to score in the corner.
The 33-year-old added a difficult conversion to lead 10-3, but Scotland hit back immediately.
Tim Nanai-Williams threw a loose pass that was collected by Seymour after Paul Perez knocked it forward onto the winger's hand, the ball looped over Perez's head and Seymour gathered to score.
Laidlaw drew his side level with the conversion, but Scotland had not sorted out the restart.
Cotter's side were penalised for being offside inside their 22m. Samoan skipper Kahn Fotuali'i took a quick tap before popping to the on-running Leiataua to crash over the whitewash.
Pisi missed the conversion attempt but Samoa led by five and by now the alarm bells were ringing.
Laidlaw reduced the score with his second penalty but 15-13 became 20-13 six minutes later when Lee-Lo touched down in the left-hand corner.
A jinxing run from Lee-Lo in the build-up saw the inside centre beat four defenders before the move lost momentum.
Samoa gathered their composure, regathered the ball and Lee-Lo, collecting a pass from his centre partner George Pisi to score.
Tusi Pisi could not add the two points, but Samoa were a converted try in front and Scotland reeling.
Laidlaw and Pisi traded penalties either side of a yellow card for Ryan Wilson after the TMO picked up a stamp on Maurie Fa'asavalu's arm. Wilson was lucky not to see red.
In keeping with the frantic nature of the game, Scotland somehow hit back on 32 minutes. They were awarded a penalty and Finn Russell kicked for the corner.
The resulting line-out saw Jonny Gray collect and the forwards set-up a driving maul which Samoa had no answer.
Kiwi-born Hardie touched down, Laidlaw drew the Scots level with his second conversion and the momentum had swung back in favour of the Brits.
Samoa then thought they had scored a fourth try through loose-head prop Sakari Taulafo, but it was chalked off for an illegal clear-out of the Scotland skipper on the try-line.
Referee Jaco Peyper was playing advantage to Samoa and Pisi kicked an easy three points in front of the posts, 26-23 at the break.
The second half saw Scotland fight back, gain control and ascendency. Two Laidlaw penalties in the opening 15 minutes gave Scotland the lead for the first time in the match.
Samoa's penalty count reached 14 inside the hour and would prove costly in the end.
The Scotland captain had a chance to extend the lead to six but missed a difficult kick from the halfway line and the score stayed 26-29.
Somehow, Samoa were still enjoying possession and territory but continued to leak penalties.
Laidlaw momentarily lost his bearings, missing a second penalty which kept the islanders in the game.
As the clock ran down, WP Nel now on, thought he had scored but was adjudged to have been held up by the Samoan captain, who got a leg underneath the ball.
However, Scotland had the penalty and opted for a scrum. Samoa's scrum back-peddled, Laidlaw picked up at the back of the set-piece, darted left and scored under the posts.
The scrumhalf added the two and the goal gave his team a ten-point lead.
Samoa scored a consolation bonus-point fourth try and despite Patrick Faapale's conversion, the game was up and Scotland had reached the knockout stages.
Final Score Samoa 33 (26) Scotland 36 (23)
Tries - Tusi Pisi, Leiataua, Lee-Lo, Matu'u,
Pen - Tusi Pisi (3)
Con - Tusi Pisi, Faapale
Tries - Seymour, Hardie, Laidlaw
Pen - Laidlaw (5) Con - Laidlaw (3)
Referee: Jaco Peyper (RSA)
Assistant referees: JP Doyle (ENG), Marius Mitrea (ITA)
TMO: Ben Skeen (NZL)
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 (captain), 8 Alafoti Fa'osiliva, 7 Jack Lam, 6 Maurie Fa'asavalu, 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 Faapale, 23 Ken Pisi.
Scotland 15 Stuart Hogg, 14 Sean Maitland, 13 Mark Bennett, 12 Matt Scott, 11 Tommy Seymour, 10 Finn Russell, 9 Greig Laidlaw (captain), 8 David Denton, 7 John Hardie, 6 Ryan Wilson, 5 Jonny Gray, 4 Richie Gray, 3 Willem 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.