Wales had to sustain prolonged pressure from Scotland before pulling clear at the Principality Stadium.
Despite scoring the game's first try through Gareth Davies, Wales trailed 16-13 going into half time.
Dan Biggar - showing no signs of the ankle injury which had made him an injury concern for this game - levelled the scores, before Jamie Roberts and George North crossed to give Wales breathing space.
A late try from Duncan Taylor brought the visitors back to within four points.
But it was too late to stop Gatland's men from claiming a hard fought victory. They sit second in the Six Nations table but will go third if England defeat Italy on Sunday.
Wales: tries G. Davies, J. Roberts, G.North; cons: D.Biggar (3) Pens: Biggar (2)
Scotland: tries: T. Seymour, D. Taylor; cons: Laidlaw (1), Hodge (1); Pens: Laidlaw (3)
It was a day of mixed results for the Welsh football sides this afternoon, with Swansea falling to defeat against Southampton, Cardiff drawing at Charlton and Newport and Wrexham picking up home victories.
A Shane Long goal mid-way through the second half ensured that Swansea head coach Francesco Guidolin tasted his first defeat as manager, in a result which sees the Premier League side just three points above the relegation zone.
Elsewhere in the Championship Cardiff remain 9th in the table, 5 points off the promotion spots following a 0-0 draw against Charlton at The Valley.
In League 2 Newport recorded a rare home win thanks to a Scott Boden strike against Carlisle and in the National League Wrexham consolidated their mid-table position with a 2-0 win over Bromley.
Charlton Athletic were left red-faced when the club showed a face of Alan Campbell during a minute's applause for Graham Moore.Read the full story ›
A close range strike from Newport forward Scott Boden was enough to give Warren Feeney's side a 1-0 win over Carlisle this afternoon.
The win, which will help ease County's relegation fears, is the first picked up at Rodney Parade since November.
Newport stay 20th in League Two, seven points off the drop zone.
Shaun Edwards says there'll be no room for complacency when Wales take on opponents they haven't lost against since 2007.Read the full story ›
Former Wales international Jack Collison has announced he has retired from football at the age of 27.
I'm officially retired as of today... Here is a short statement...https://t.co/YlwPsOUxvp thanks for all the support
In a statement on his website, the former West Ham midfielder admitted he had reached the decision due to a persistent knee injury which has dogged his career since his early days as a professional.
...the time has finally come to say, enough is enough, and admit my body can no longer cope with the demands of modern day football. The nights where I wake up in pain, or the mornings where I struggle to walk will be a constant reminder that I was lucky enough to play the game I love. That I put my body on the line time and time again to live out my dreams in front of the world.
Rugby fans told to expect queues of up to 2 hours to get home as thousands pour into the city for Wales' first Six Nations home game.Read the full story ›
In the Pro12, the Scarlets have defeated Edinburgh 22-21 after taking a narrow lead in the final few minutes.
Wales U20 have defeated Scotland U20 18 -15 this evening in their second match of their Six Nations campaign.
Swansea must learn the Italian art of defending to continue their climb up the league table, says head coach Francesco Guidolin.Read the full story ›