Scotland stared down the prospect of an agonising defeat to Italy, only to run the length of the field and secure a precious bonus point win to round off their Six Nations campaign.
Blair Kinghorn scored a hat-trick of tries but the visiting Azzuri thought they would be claiming a famous win as they pressed for a go-ahead score with just seconds to play.
However a thrilling counter by the Scots, finished off by Kinghorn, ensured a best-ever finish for Gregor Townsend’s men in the championship.
Townsend was unable to call on a wealth of experience, with influential backs Stuart Hogg and Finn Russell missing, as well as first choice second rows Richie Gray and Grant Gilchrist.
Ollie Smith won only his third cap at full back, with the versatile Kinghorn selected at fly half.
Tommaso Allan missed a straightforward penalty from the 10m line early in the game but Italy came back again and Allan slotted his next attempt after Scotland collapsed the maul.
Knowing they needed a bonus point win to secure third place, Scotland turned down chances to kick at goal as they chased the try line.
They were rewarded after 12 minutes when Huw Jones fed Duhan van der Merwe who acrobatically leapt beyond the tackle of Paolo Garbisi to score at the corner.
A ruck penalty immediately from kick off allowed Allan to kick Italy back to a 6-5 lead.
Prop Marco Riccioni was yellow carded on the 28th minute after Italy were repeatedly penalised at the scrum and Scotland immediately exploited the extra man advantage as Ben White popped his half back partner Kinghorn over to score.
The visitors held out with 14 men and repelled a late Scotland attack just before half time to go in 12-6 at the break.
Scotland quickly got to work with their third try of the afternoon after the turnaround when a series of carries near the goalline eventually opened the space for Kinghorn to grab his second score of the match. The Edinburgh man converted to make it 19-6 with 45 minutes on the clock.
Italy clawed their way back into the contest just after the hour mark when Allan gathered a grubber kick on the left wing to score in the corner. The missed conversion meant the scoreboard read 19-11 with just over a quarter hour to play.
Garbisi then kicked another three to reduce the deficit to five points and fuel belief in the Azzurri ranks.
Scotland’s play became ragged and both teams struggled to hold sustained possession as the game entered its decisive phase.
Italy then banged at the door with a series of huge carries on the Scotland goalline before a knock-on brought relief to the majority of the capacity Murrayfield crowd.
The clock was past 80 minutes but the Scots were not done.
After winning a penalty advantage Ali Price launched an attack from their own five metre line and Van Derwe tore up field before releasing Kinghorn to score his hat-trick try and secure the bonus point which ensured Scotland end the Six Nations on 15 points and in third place.
Scotland Player Ratings
Ollie Smith 7 – Able to show off his electric footwork on the counter attack and beat four defenders.
Kyle Steyn 6 – Made a lot of ground along the right wing and sharp in defence.
Huw Jones 7 – Elusive running opened up lanes for teammates to exploit, none more so than when he sent Van der Merwe through to score.
Sione Tuipulotu 7 – Important playmaking role in absence of Finn Russell and shared responsibility to launch attacks with Kinghorn.
Duhan van der Merwe 7 – Thrilling, flying finish to score his first try since Twickenham then set Kinghorn away at the end.
Blair Kinghorn 8 – A very different prospect to Russell at 10 but brings constant try-line threat, resulting in two scores from close quarters before a stint at 15 and that heart-racing last gasp hat-trick score.
Ben White 7 – Awareness to set up Kinghorn first try with the pack tied up in the scrum, topped off a solid campaign.
Pierre Schoeman 8 – Another monster shift from the Murrayfield favourite, dominant in the scrum, made 13 carries and 11 tackles.
George Turner 6 – A couple of uncharacteristic wayward throws and utilised more sparingly in carries after a long championship for the hooker.
Zander Fagerson 7 – Ups and downs the scrum but a force in contact.
Sam Skinner 6 – Got around the park on his first start of the spring.
Jonny Gray 6 – Workhorse made 14 tackles and 12 carries in his hour on the field.
Jamie Ritchie 7 – Struggled to get on the right side of the referee and looked frustrated at times.
Hamish Watson 6 – Carrying threat was contained but showed his muscle in tight areas
Jack Dempsey 8 – Led the Scotland team in carries as he brought his explosive physicality to the party.
Replacements 6 – Ben Healy showed up well on debut and Ali Price made a difference coming on for White. Changes around the paddock created some disorganisation.