A Scottish error on their own lineout allowed Wales to score the first try just after the half hour mark as prop Rhys Carre powered over after the hosts had finally breached desperate defence from the visitors.
To compound Scottish woes, maverick flyhalf Finn Russell, whose early penalty had put them ahead, limped off with an injury. Adam Hastings, who came on for Russell, reduced the deficit to 7-6 at halftime with a penalty.
Scotland had another penalty opportunity on the hour mark to take the lead but gambled instead on kicking for touch, seeking to get closer to the Welsh goalline.
Jonny Gray won the subsequent lineout and a rolling maul marched the ball over the line with replacement hooker Stuart McInally claiming the try.
Hastings missed the conversion, however, and Wales reduced the difference to a single point when Leigh Halfpenny slotted over a penalty.
It was Scotland who finished strongly in the swirling wind, however, to secure a morale-boosting success. They won a penalty in the last minute and captain Stuart Hogg kicked it with the final action of the game to make sure of victory.
"We are absolutely delighted, we knew we would come down here and put on a performance. We'll enjoy this one," Hogg said.