The scoreline suggests a comfortable win but it was far from it as Italy pushed the Scots until the final whistle on Saturday.
With the clock almost in the red and the hosts leading 19-14, Italy were camped on the Scotland try-line before a breakaway snatched the game away from them.
Blair Kinghorn's hat-trick score was part of four tries from Gregor Townsend's men, with Duhan van der Merwe claiming the opening score.
Tommaso Allan went over for Italy's only try of the game as they finish the Six Nations in last spot, but will take plenty of positives from the campaign.
Italy had a chance to get the scoreboard ticking when they awarded a penalty on the 10-metre line in the fourth minute but Allan's kick drifted left.
Four minutes later, however, Allan got the Italians off the mark when he kicked a penalty from the 22.
The Scots sparked into life in the 13th minute when Van der Merwe received an offload from Huw Jones wide on the left and shrugged aside the challenge of Paolo Garbisi to touch down. Kinghorn missed conversion attempt.
The Italians were back in front three minutes later when Allan scored another penalty.
The visitors were forced into a change in the 23rd minute when Edoardo Iachizzi went off injured and was replaced by Niccolo Cannone.
Six minutes later, they suffered a further blow when prop Danilo Fischetti was sin-binned for repeated scrum infringements. Winger Simone Gesi was temporarily sacrificed as Pietro Ceccarelli was brought on to reinforce the front-row.
Scotland made the extra man count within a matter of seconds as Ben White took the ball from the base of the scrum and played in Kinghorn, who spotted a gap and dived over. The number 10 duly converted his own try.
The hosts continued on the front foot early in the second half and Kinghorn got himself a second try just four minutes after the restart following another assist by White. The try-scorer again added the extras.
Italy got themselves back in the match when Allan went over for a well-worked try on the left. Allan missed the chance to bring the Italians within a converted try of victory when he missed his conversion attempt.
But four minutes later, team-mate Garbisi took over kicking duties and sent a penalty between the posts from just outside the 10-metre line to reduce the deficit to just five points.
Italy piled on the pressure in the closing stages and looked like they might be about to force a victory before Scotland broke away in the last action of the match, with Kinghorn racing behind the posts after being handed a clear run by Van der Merwe. The number 10 capped a memorable afternoon for himself with a close-range conversion.