Wales edged out 14-man Scotland in a mesmeric thriller at Murrayfield to maintain their 100% start to their Six Nations campaign.
Tries from Darcy Graham and Stuart Hogg had the Scots in a 17-8 half-time lead.
But a frantic seven minutes saw the hosts have a try disallowed and Zander Fagerson sent off, while the visitors went over twice to swing the momentum.
A Wyn Jones try was bookended by two from Louis Rees-Zammit, the latter proving crucial in the bonus-point win.
Scotland claimed a losing bonus point too, but 20-year-old Rees-Zammit's efforts were the highlight of the encounter.
His first try came just moments before the break to offer hope for the Welsh, while Liam Williams' try on 52 minutes came just three minutes after Gary Graham's score was ruled out.
Scots answer early questions
It's hard to recall a time in living memory when Wales went into a Test against Scotland as clear underdogs - with good reason as it turned out - but they made a bright enough start even if their pressure only delivered three points from Leigh Halfpenny's boot. There was plenty of grunt but precious little craft - and there was a gulf between the sides in that regard.
Finn Russell levelled it on the 10-minute mark as Scotland slowly but surely turned the screw on the injury-hit visitors. Scotland, seeking a fifth straight win in the championship for the first time since 1986, struck the first significant blow of a bitterly cold day when Darcy Graham went over for the first try.
It was a beauty, too. A score borne out of vision and anticipation and ambition. Russell started it with a little break and offload to Jonny Gray who galloped in behind the Welsh defence. The big man, exceptional at Twickenham, had support coming in waves.
The key men were Ali Price, who spotted Wales' flat defence and dinked a gorgeous chip over the top, and Graham, who read his scrum-half's mind and gobbled up the dropping ball. Halfpenny tried to recover his ground, but it was too late. Russell's conversion put the Scots seven points clear.
This reborn Scotland side came again soon after. A scrum, a wraparound in midfield, a chip ahead from Hogg which should have been dealt with by Halfpenny, but wasn't. The full-back, so often the scourge of the Scots, slid to deal with the loose ball but then nightmarishly allowed it squirm from his grip. Hogg seized on it and scored. Russell made it 17-3 and the questions about Scotland's ability to back up the Twickenham win were being answered.
They got sloppy for a spell afterwards, though. Penalties flowed and so, at last, did Wales, Nick Tompkins and Liam Williams putting Rees-Zammit over in the corner just before the break. A nine-point game now.
Drama engulfs pulsating second half
Early in the new half it looked to all the world as if that gap would stretch in Scotland's favour when Gary Graham piled over at the posts, but Scott Cummings was done for obstruction and everything turned from there.
Wales came downfield, launched a devastating maul, threw a dummy runner and some deception in midfield, and Rees-Zammit went through a gap and fed Williams to score. Callum Sheedy banged over the extras, 17-15.
Then, drama. Fagerson walked when his shoulder connected with Wyn Jones' head at the breakdown. Scotland down to 14, Wales with a one-man advantage for the second week running. Another powerful Welsh maul added to Scotland's pain. The sinned-against became the scorer. Try for big Wyn - and a three-point lead for Wales.
This pulsating game was far from done, though. The 14 men got themselves back up the pitch, piled the heat on Wales under their own posts and then struck out, Russell finding Hogg who took Owen Watkin on the outside to score. It was a terrific finish from the captain. Russell, from 41 metres out and away on the angle, rifled over a valuable conversion. Scotland now had a four-point lead.
In keeping with the mini-classic we were watching, Wales regained the lead minutes later and again it was the sensational Rees-Zammit at the heart of it. This was all about the brilliant wing. He sped down the touchline, chipped ahead, gathered and outpaced the retreating Scots, Hogg among them. Wonderful.
Sheedy missed another conversion so the gap stayed at one. Ten minutes to go. Terrific. Scotland's 14 threw everything at Wales but they defended stoutly in the closing minutes.
No way through, no way back for Scotland, not even when Duhan van der Merwe looked to be away in the closing seconds only to be tap-tackled to the floor by Watkin. A mammoth injury list they may have had, but this was a gargantuan victory for Wayne Pivac's men.
Man of the match: Louis Rees-Zammit
'I'm loving playing on this stage' - what they said
Scotland captain Stuart Hogg speaking to BBC Scotland: "I thought we were excellent in large parts of that game. We talked a lot during the week about our discipline. Conceding one penalty is fine, conceding four on the bounce is unacceptable.
"Wales were outstanding, they took their opportunities but we gave them to them.
"It's pointless me whinging about the red card, what's done is done."
Wales' man of the match Louis Rees-Zammit told BBC One: "We've come a long way from the last Six Nations campaign and worked so hard in training. It's hard to come up here and get a win.
"I'm thoroughly enjoying it, the whole team have helped me settle in and I'm loving playing on this sort of stage."
'Rees-Zammit was the spark' - analysis
Glasgow Warriors & Scotland hooker Fraser Brown: "Some decisions are completely subjective. Either give the officials full autonomy to make their own decision about it, and accept that there will be differences in how they see it, or say absolutely any contact to the head is a red card and we end up playing games with eight or seven players.
"People don't want that because it ruins the spectacle but we have to think, are we doing this for the players' safety or are we doing it just for lip service?"
Former Wales fly-half James Hook: "A lot better performance by Wales this week, we showed a lot more. Rees-Zammit was the spark that everyone knows what he can do, and he showed it today."
Line-ups
Scotland: Hogg (capt); D Graham, Harris, Lang, Van der Merwe; Russell, Price; Sutherland, Turner, Z Fagerson; Cummings, J Gray; Thomson, Watson, M Fagerson
Replacements: Cherry, Kebble, Nel, R Gray, G Graham, Steele, Van der Walt, H Jones
Wales: Halfpenny; Rees-Zammit, Watkin, Tompkins, Williams; Biggar, Davies; W Jones, Owens, Francis; Beard, AW Jones (capt); Wainwright, Tipuric, Faletau
Replacements: Dee, R Jones, Brown, Rowlands, Botham, Hardy, Sheedy, Haloholo
More to follow.