Williams' second try was highly controversial
Wales (10) 30
Tries: S Williams 2, Hook
Cons: Hook 2, S Jones
Pens: Hook, S Jones 2
Scotland (6) 15
Pens: Paterson 5
A spectacular brace of Shane Williams tries saw Wales maintain their 100% start to the RBS Six Nations.
The home side dominated possession and territory and their flair saw first half tries for Williams and James Hook.
But dogged Scotland held on through the boot of Chris Paterson, the wing landing all five of his goal kicks.
Leading just 17-15 on 60 minutes, Wales changed their half-backs and regathered before Williams split the defence and squeezed in for a controversial score.
Wales began with the momentum of last week's stunning win over England, man-of-the-match Martyn Williams and Hook pouncing on a loose Scotland line-out to win their side a scrum five metres from the visitors' line.
Scotland's defence proved stout through a series of Welsh drives, and they escaped with a penalty when Tom Shanklin held the ball on the floor.
The Welsh were looking to spread the ball in front of a record crowd at Cardiff's Millennium Stadium, but Hook spun a midfield pass into the arms of Andrew Henderson.
Paterson hacked forward to the Wales line, securing the position from which the wing - restored to Frank Hadden's team this week after the miserable loss to France - opened the scoring with a 10th-minute penalty.
Wales hit back in style, Mike Phillips carrying powerfully after gathering a misjudged open-field chip from Hugo Southwell.
It's 100% certain that I scored, there's no doubt in my mind
The ball was spun left, Hook putting Lee Byrne into space with a delightful pass after Gavin Henson helped straighten the line.
Byrne's pass went behind Williams, but the winger gathered and threw a trademark side-step to cross for the opening try, converted by Hook.
The visitors saw 50-cap man Nathan Hines sin-binned for foolishly lashing out at Byrne when he was held at a ruck.
The 14 men held out, Hook and Paterson exchanging penalties after his return to leave Scotland relieved with a scoreline of 10-6 at the break.
The visitors were soon back to within a point, Paterson slotting an easy penalty after a bullocking run from Allister Hogg, an impressive first-half injury replacement for skipper Jason White.
But Williams broke through a ball-watching defence, and when scrappy ball was flung left Hook saw Ross Ford and Euan Murray in front of him.
The fly-half went for the front-rowers and squeaked through the gap, touching down then converting his own score.
Hook was replaced with 20 minutes of the game to go
The unerring boot of Paterson clawed back two more penalties, though, cutting the gap to two points and prompting Wales coach Warren Gatland to replace half-backs Hook and Phillips with Stephen Jones and Dwayne Peel.
They helped keep Wales anchored in their opponents' half, Jones eking his side further ahead with a 65th-minute penalty.
Confidence rose in the home side, and after an impressive build-up the ball came to Williams who spotted half a yard of space in midfield.
The wing sailed outside Henderson and Southwell, before a desperate Nikki Walker tackle forced him to ground from mid-air with his body outside the touchline for a spectacular and hotly disputed try awarded by video referee Carlo Damasco.
Stephen Jones converted and added a penalty to complete a 100% kicking return from both teams, while his side showed the determination to deny the Scots a consolation try after a late rally.
Gatland will try to keep Welsh expectations in check, but with a home game against Italy in two weeks and a Triple Crown game in Dublin on 8 March, that seems unlikely.
Watch the match in full on BBC iPlayer for seven days from Saturday (UK users only)
Wales: Byrne, Roberts, Shanklin, Henson, S. Williams, Hook, Phillips, D. Jones, Bennett, A. Jones, Gough, Evans, Thomas, M. Williams, R. Jones.
Replacements: Parker for Shanklin (71), S. Jones for Hook (58), Peel for Phillips (58), Jenkins for D. Jones (54), Rees for Bennett (58), D. Jones for Gough (73), Delve for R. Jones (62).
Scotland: Southwell, Walker, De Luca, Henderson, Paterson, Parks, Blair, Jacobsen, Ford, Murray, Hines, Hamilton, White, Barclay, Brown.
Replacements: Danielli for Walker (74), Cusiter for Blair (73), Thomson for Ford (73), MacLeod for Hines (62), Hogg for White (32). Not Used: Kerr, Morrison. Sin Bin: Hines (16).
Referee: Bryce Lawrence (New Zealand).