The hosts led 20-17 at the break in Colwyn Bay but Scotland looked set to claim the spoils when Freddie Douglas crossed for his second try.
That was until Walker Price completed a double of his own to put Wales back in front before Rhodri Lewis sealed the victory with four minutes to play.
Wales started strongly but after captain Harri Ackerman had a try chalked off for an earlier forward pass, Scotland duly established themselves in Welsh territory and drove Elliot Young over from a lineout maul.
Harri Wilde penalty’s cut the deficit and the home side had the lead shortly after as Huw Anderson benefited from an ingenious Louie Hennessy offload that kept play alive.
The sides traded two further tries apiece before half-time, Freddy Douglas and Young going over for the visitors either side of Price and Morgan Morse as the non-stop action continued.
Undeterred by being behind, Scotland marched deep into their opposition's 22m early in the second period and used their set piece to buffer Wales closer and closer to their own try line.
The pressure paid off when Kerr Yule crashed over from close-range and it took 20 minutes for Wales to respond through captain Ackerman, who powered over to the delight of the home crowd.
Scotland went back in front through Douglas but soon saw Alex O’Driscoll shown a yellow card for a deliberate knock-on.
Wales took full advantage of that extra space to help Price to his second try of the evening as Harri Ford found the wing with a stunning pass to the left wing, the replacement playmaker duly slotting the conversion from the touchline.
With four minutes remaining, scrum-half Lewis latched onto a chip over the defence from Harry Rees-Weldon to put the result beyond doubt and ensure Wales will head into their Round 2 clash with England full of confidence.