The visitors were yet to score a try in the competition and their inefficient attack was on display as a knock-on from Magnus Bradbury scuppered hopes of an early score, before Hastings missed a comfortable penalty from within Italy's 22.
Italy fell to a 25th consecutive defeat in the tournament and are set to take the wooden spoon for the 15th time.
"We're coming off the back of two defeats".
Hastings sent a penalty kick wide after eight minutes as the Italians looked risky with a Matteo Bellini counter-attack, off-loading to Jayden Hayward before Scotland reacted and sent Braam Steyn into touch.
The Exeter Chiefs fullback broke through with a brilliant solo run down the right wing.
Italy's Tommaso Allan fared no better when his long-range penalty just before halftime came back off the outside of the post. The try was ruled out after a review showed Sam Johnson's final pass was forward.
The second-half was initially a more turgid affair but a try from centre Chris Harris was enough to spark inspiration for Scotland who carried their momentum to the end of the game.
Italy continued to fight but they suffered a second shutout of this year's competition, their frustration compounded by Federico Zani being shown the yellow card for a risky tackle on Grant Gilchrist, before Hastings went over late on, following Scotland's 21st turnover against the tiring Azurri.
Despite a rare win on the road, with the opposition being held to zero, the mood amongst Scotland fans in the bars and restaurants around the Stadio Olimpico and on social media on Saturday evening was not particularly positive, with a lot of frustration being expressed about the fragmented nature of Scotland's overall performance.
"The game was still an arm-wrestle at 10-0", said Townsend.
Stuart Hogg believes Scotland can finally click into gear against Italy after a fumbling start to his first Six Nations' captaincy.
After halftime of the scrappy match in flawless conditions, fellow backs Chris Harris and Adam Hastings also dotted down.