Wales staged a remarkable fightback to inflict torture on Scotland at the Millennium Stadium.
The home side looked down and out when they trailed 24-14 with only three minutes of normal time left, but tries by Leigh Halfpenny and Shane Williams - his 49th for Wales - clinched an astonishing win.
Scotland looked to have done enough to reduce Wales' RBS 6 Nations title hopes to ruins by ending an eight-year wait for victory in Cardiff, but they ended the game with 13 men after substitutes Scott Lawson and Phil Godman were sin-binned in rapid succession.
Fly-half Dan Parks delivered a supreme tactical display that also included two drop-goals and a penalty double, while flanker John Barclay and substitute wing Max Evans scored first-half tries and Chris Paterson slotted a conversion.
But Wales, who had earlier claimed a Lee Byrne try, prevailed as fly-half Stephen Jones kicked 16 points, leaving Scotland crestfallen following two successive Six Nations defeats.
It was rough justice on the Scots, who dominated most of the game in arguably their most complete performance during Andy Robinson's coaching reign.
However they could not finish Wales off, despite having them on the ropes for so long, as the home side completed one of Six Nations rugby's greatest comebacks.
Paterson led Scotland out, in tribute to him becoming the latest member of Test rugby's 100-cap club, joining such illustrious names as George Gregan, Philippe Sella and David Campese.
An open stadium roof - a rarity these days for Wales home games - revealed a leaden sky, but no sign of the rain which Wales boss Warren Gatland suggested Scotland had been hoping for.
The Scots quickly showed they did not require wet weather to assist them tactically as they stunned Wales with a ninth-minute try.
Paterson, who had received lengthy treatment for a knock to his shoulder, regained his feet in time to see Barclay smash through the combined defence of James Hook and Gareth Cooper.
Barclay's power was too much for them as he sprinted over for Scotland's first try since their opening autumn Test victory over Fiji three months ago.
Paterson added the conversion - his 35th successful Six Nations kick in a row - and blundering Wales could have few complaints at an early seven-point deficit.
And it got worse for the home side, despite Jones opening their account with a 15th-minute penalty.
Wales were horribly disorganised in defence, and Scotland took advantage with a second try after Parks played the role of creator following a neat drop-goal.
His clever kick behind the Welsh defence saw Max Evans - on the field as a replacement for his brother Thom - react quickest and ground possession just before the dead-ball line.
Referee George Clancy needed confirmation from television match official Geoff Warren before the try was awarded, and although Paterson's long kicking sequence ended through a missed conversion, Scotland quickly extended their lead.
Parks cancelled out Jones' second penalty for an 18-6 advantage, and Paterson then departed the action with Evans returning as a permanent, rather than temporary, substitute.
It was a sad way for Paterson's afternoon to end, yet he would have been thrilled with Scotland's dominant performance as he made his way off.
Wales pressed in search of a try, but the game was held up when wing Thom Evans suffered a serious-looking leg injury following a shuddering midfield collision with Byrne.
The Glasgow player was carried off on a stretcher, appearing to be in a bad way, and it meant scrum-half replacement Mike Blair being pressed into emergency wing duty.
Wales piled on the pressure as half-time approached, but their game continued to be spiked by basic handling errors prior to Jones slotting a third penalty.
Scotland were good value for their 18-9 interval advantage, and Parks immediately extended it through another penalty after Cardiff Blues scrum-half Richie Rees replaced Cooper.
Gatland, his patience close to running out, then made a triple substitution, sending on lock Bradley Davies, prop Gethin Jenkins and hooker Huw Bennett as Wales looked to lift the tempo.
And it had the desired effect as Shane Williams' arcing run and superb pass allowed to Byrne to cross in the corner, cutting Wales' deficit to seven points with 24 minutes left.
Parks though, the game's dominant figure, booted a second drop-goal, before Lawson was sin-binned and Halfpenny's late try, converted by Jones, set up a nerve-shredding finale as Jones drew Wales level with a penalty.
Then Williams struck during the game's final passage of play - raising his arm in triumph before crossing the line - and mayhem broke out around the stadium.Reuse content