Scotland notched their first win on home soil for five years to set up a European Nations Cup group decider against Ireland on Friday.
The Scots and Welsh scored four tries apiece in a thriller at a sodden Old Anniesland, Glasgow.
But it was man-of-the-match Danny Brough of Hull who made the difference for the hosts with four penalties and a conversion.
The winners of Friday's match will play England or France in the final.