Josh Adams and Owen Watkin touched down in Rome following the break with Dan Biggar laying the groundwork for victory with 14 of his side’s points.
Italy crossed for two tries through Braam Steyn and Edoardo Padovani but the Azzurri fell to their 19th consecutive defeat in the tournament.
“It wasn’t a great performance today but sometimes you have to win ugly,” said Gatland.
“We got out of jail. We weren’t as accurate as we could. We didn’t play that well but we’ll take a win and move on and start thinking about England.
“We were looking at the bigger picture, we wanted to everyone an opportunity to be involved in the first two games,” the New Zealander said.
Wales made it two wins out of two after last weekend’s 24-19 win over France in Paris, and go top of the Six Nations table.
– ‘Set up nicely for England’ –
“We want to have as good a World Cup as we can, there’s no regrets, we’ve won two from two matches and now have a couple of weeks to set up nicely for the England match.”
They last achieved 11 consecutive victories in 1910, and will bid to break the record against England at the Principality Stadium in two weeks’ time.
“We didn’t speak about it this week,” said Gatland. “We’ll probably speak about it before England.
“We’ve got a chance at home and there will be some atmosphere.”
Gatland had rung the changes with ten new faces in the starting lineup in the Italian capital from the side that came from 16-0 down at half-time to beat France last weekend.
Jonathan Davies captained Wales for the first time with regular skipper Alun Wyn Jones starting on the bench as Wasps flanker Thomas Young and Leicester winger Jonah Holmes making their Six Nations debut.
Wales looked to be cruising in the opening half an hour with Biggar slotting four penalties, the first within the first two minutes, as the visitors dominated possession.
But Steyn got Italy back into the game with a try after half an hour in the Stadio Olimpico which Allan converted before his penalty hit the post to give Wales a 12-7 at the interval.
Wales’ usual skipper Alun Wyn Jones came off the bench after 50 minutes and helped lift the side with his imposing on-field presence.
Scrum-half Aled Davies launched a break from a scrum down the right with Liam Williams setting up Adams for a try which Biggar converted.
Italy responded with an Allan break teeing up Padovani’s touchdown.
Italy followed their 33-20 loss to Scotland in Murrayfield by extending their losing streak in the competition going back to February 2015.
“Obviously we’re very disappointed it was a match in which we had our chance in the second half,” said Italy coach Conor O’Shea.
“It’s bloody hard. We have the ability, but when you don’t have the confidence it’s difficult.
“We want to win the war but have lost another battle today.”
O’Shea’s side next host Ireland in Rome in two weeks time after the Irish bounced back from their opening loss to England to beat Scotland 22-13.
Download our app and read this and other great stories on the move. Available for Android and iOS.