Scotland concluded their Six Nations campaign with a dramatic bonus-point win over Italy at Murrayfield to all but guarantee a third-place finish in the Championship.
A stunning Duhan van der Merwe finish and Blair Kinghorn score - with Italy down to 14 - opened a half-time lead.
Kinghorn plunged over after the break but Tommaso Allan's try and a Paolo Garbisi penalty brought Italy within five and sparked a frantic finale.
However, Scotland survived a late onslaught and streaked away from their own line with the clock in the red, Kinghorn bursting over after a coruscating break to complete his hat trick.
After painful near-misses in the championship, this was another sickener for the Italians, a team that looked in danger of being beaten comfortably before coming storming back and scaring the life out of the Scots.
The game had been stodgy but the endgame was breathless as Italy pounded the Scotland line. A few minutes remained and a try would done for the hosts. Italy threw the kitchen sink into it for two and three minutes but couldn't get it done.
The agony for the visitors was the breakaway that saw Scotland get their bonus-point victory, run in by Kinghorn, who has now scored two Six Nations hat-tricks against the Italians.
It should be enough for Scotland to finish third - England would now need to record a bonus point win in Ireland and score heavily to have any chance of denying Gregor Townsend's side third place.
Messy throughout, but Scots find relief
This was messy from the start. A succession of penalties given away by Scotland on the floor, a maul that shunted them backwards, a lead given to Italy from the boot of Allan that could have been more had they been more ruthless.
Van der Merwe calmed local nerves soon after with a sensational finish in the corner. Without the defence-splitting brilliance of Finn Russell, Scotland lacked imagination for much of the day, but where there's Van der Merwe there's hope.
Scotland had been banging away in Italy's 22 for an age. Eventually, from a tap penalty they went down the short side, Jamie Ritchie spilled it backwards in the tackle, but Huw Jones came sweeping in behind and put Van der Merwe away.
The finish was something special. A leap in the air in a yard of space did for the last defender, Paolo Garbisi, and Scotland were on the board.
Allan put Italy back in front with another penalty but that was the last we saw of them as an offensive force for the longest time.
Scotland lived in Italy's 22 for the rest of the half but toiled to take advantage. Italy survived on the back of their defence and their offending and the home team's inability throw something different at them - a little deception, a modicum of confusion.
Relentless collapsing of scrums in their own 22 cost Italy a man. Angus Gardner had warned them, but they carried on and Marco Riccioni walked.
In the next wave, White put Kinghorn in, the fly-half cutting inside the cover to score. He then added the conversion.
Kinghorn is not a natural 10 and can't run a show from that position like Finn Russell can. He's a class player, though. And he showed it again early in the new half.
More Scotland pressure pushed Italy backwards - they missed 23 tackles in the first half alone - and when the space presented itself, Kinghorn bust through Juan Ignacio Brex and Sebastian Negri to touch down.
Another conversion brought his tally to 14 and stretched Scotland's lead to 19-6.
At that point you expected the Scots to drive on. Townsend used his bench in search for more momentum but everything stalled. The line-out started to malfunction (again) and Italy started to sense weakness.
Garbisi's gorgeous grubber down the left touchline and in behind Scotland found Allan, who ran away to score. You could feel the anxiety in Murrayfield now.
Allan failed with his conversion but Garbisi put over a fine penalty three minutes later after Scotland descended into a mess in defence. A five-point game now.
There was more to come. Much more. That last stand by the Italians. That last score by the Scots. And the sound of 67,000 panic-ridden home fans breathing heavily at the end.
'We dug it out in the end' - reaction
Scotland head coach Gregor Townsend on BBC One: "You've got to trust that the players will front up defensively, which is what they did. To win a penalty at the scrum was great to see, and the try was even better.
"It's been an eventful Six Nations! France was a really encouraging performance; the last two weeks maybe weren't as good overall. You get that in sport, and we're just glad we finished with a win."
Scotland captain Jamie Ritchie on BBC One: "Italy have deserved more from this tournament, they've played a lot of good rugby and they put us under huge amounts of pressure. I'm delighted we won that.
"Before the tournament, I said five good performances; we got four and a half. Today was a tough one, it was a solid performance. We dug it out, and we did well in the end. Hopefully we're third behind the two top teams in the world."
Italy head coach Kieran Crowley on BBC One: "Scotland finished their opportunities, we didn't finish ours. We keep turning up at the office and hopefully a bounce will go our way one day.
"It was one hell of a game - they gave it everything, we gave it everything. It's not for lack of effort. If you look at all five games, we've had opportunities but haven't effected them. It's something we can build on."
Scotland: 15-Smith; 14-Steyn, 13-Jones, 12-Tuipulotu, 11- Van der Merwe; 10-Kinghorn, 9-White; 1-Schoeman, 2-Turner, 3-Zander Fagerson, 4-Skinner, 5-Jonny Gray, 6-Ritchie (capt), 7-Watson, 8-Dempsey
Replacements: 16-Ashman, 17-Sutherland, 18-Nel, 19-Cummings, 20-Matt Fagerson, 21-Price, 22-Healy, 23-Redpath
Italy: 15-Allan; 14-Bruno, 13-Brex, 12- Menoncello, 11-Gesi;10-Paolo Garbisi, 9-Fusco; 1-Fischetti, 2-Nicotera, 3-Riccioni, 4-Iachizzi, 5-Ruzza, 6-Negri, 7- Lamaro (capt), 8-Lorenzo Cannone
Replacements: 16-Manfredi, 17-Zani, 18-Ceccarelli, 19-Niccolo Cannone, 20-Pettinelli, 21-Zuliani, 22-Alessandro Garbisi, 23-Morisi
Referee: Angus Gardner (Australia)
Touch judges: Matthew Carley (England) & Craig Evans (Wales)
TMO: Brett Cronan (Australia)