Early in the second half in Rome, Scotland trailed by 12 points, but fought back to snatch a 29-27 victory thanks to Greig Laidlaw's late penalty.
Tommaso Allan had kicked Italy ahead in a dramatic final 10 minutes, before Laidlaw's decisive strike.
Former Scotland U20 fly-half Allan contributed 22 points, including a try in each half, and also set up Matteo Minozzi to touch down.
Fraser Brown, John Barclay, Sean Maitland and Stuart Hogg scored for the Scots, who earned a try bonus point.
Following home triumphs over France and England, the Scots finish their campaign with three wins from five.
"There wasn't a panic - at least not until they scored straight after half time!" said Hogg after the match.
"Then there was a panic! No, with the character in this squad I knew we could come back fighting and as soon as we got that try off Sean Maitland I felt then that we were very much in control and we wanted to keep the game flowing as much as we could and the tries would come on the back of it. The forwards were outstanding. We finish off the tries but the boys up front do all the hard work and full credit to them."