Wales piled fresh misery on Ireland just four months after knocking them out of the World Cup by claiming a 23-21 RBS Six Nations victory in Dublin thanks to Leigh Halfpenny's last-minute penalty.
Halfpenny was on target after Ireland flanker Stephen Ferris was sin-binned for a dangerous tackle on Wales lock Ian Evans.
English referee Wayne Barnes made the call despite the offence being nowhere near as bad as Bradley Davies' tackle which earlier upended Irish replacement Donnacha Ryan. Davies received a yellow card, when it could have been red.
Halfpenny held his nerve to give Wales a rare Six Nations win in the Irish capital as boos rang around the Aviva Stadium, his strike following earlier tries by centre Jonathan Davies (2) and wing George North.
Ice-cool Cardiff Blues star Halfpenny landed another penalty and conversion after taking over the duties from an out-of-sorts Rhys Priestland, who missed two penalty sitters.
Priestland's opposite number Jonathan Sexton slotted three penalties and a conversion, while hooker Rory Best and wing Tommy Bowe scored tries in a game when the lead changed hands five times.
But Ireland's Grand Slam, Triple Crown and probable title hopes were ultimately shredded by a Wales team whose last Six Nations win on Dublin soil came during a Grand Slam title-winning season in 2008.
They could, though, be without captain Sam Warburton against Scotland next weekend after he went off at half-time nursing a leg injury.
Ireland, winners of their opening Six Nations fixture on seven previous occasions, handed Fergus McFadden the number 13 shirt vacated by revered leader Brian O'Driscoll, who will miss this season's tournament as he recovers from shoulder surgery.
Wales fielded 10 of the side that ended Ireland's World Cup hopes last October, with Priestland and centre Jamie Roberts both recovering from knee problems, but injuries sidelined forwards Dan Lydiate, Gethin Jenkins, Alun-Wyn Jones and Luke Charteris.
Ireland took the lead through a third-minute Sexton penalty, but Wales responded in determined fashion as Bradley Davies and then North were only denied tries by some last-ditch tackling.
Wales kept battering away, and flanker Ryan Jones stretched over Ireland's line only for television match official Geoff Warren to rule against the visitors following repeated views from a number of angles.
Warren was called upon again just six minutes later, only this time it was a far easier call after Priestland's one-handed pass found Jonathan Davies, who touched down in the corner despite a Gordon D'Arcy challenge.
Davies scored the try which sealed Wales' World Cup win in Wellington, and his latest touchdown successfully rounded off a spell of concerted Wales pressure, handing them a 5-3 advantage after Priestland's conversion attempt hit the post.
Priestland, though, was guilty of a glaring miss as the first-half reached its midway point, striking the post straight in front from 25 metres, and Ireland stormed upfield.
Missed kicks ultimately cost Wales dear at the World Cup, yet they looked a step ahead of Ireland in thought and deed with ball in hand, and scrum-half Mike Phillips snapped a razor-sharp back division into action at every opportunity.
Ireland should have regained the lead 12 minutes before half-time, but Sexton emulated Priestland in missing an easy chance after Phillips was pulled up for obstruction on his former Ospreys team-mate Bowe.
Ireland began to grow into proceedings as the interval approached, piecing together several threatening phases, and they cut Wales open through a well-worked 38th-minute try.
Bowe cropped up on the left flank, drifted outside Alex Cuthbert and then freed Ulster forward Best for his sixth try in 55 Tests, with Sexton's angled conversion giving Ireland a 10-5 lead.
Ryan Jones took over the captaincy after skipper Warburton did not appear for the second period, and there was also a switch in the back-three, with Cuthbert going off, Halfpenny moving to wing duty and James Hook featuring at full-back.
Warburton's loss was a considerable one for Wales, continuing their run of injuries in recent weeks and giving Gatland another potential problem ahead of next Sunday's Millennium Stadium encounter against Scotland.
Sexton extended Ireland's lead with his second successful penalty, but Wales responded majestically, scoring 10 points in two minutes via a Halfpenny penalty and conversion of Davies' second try.
Priestland's third successive miss with the boot saw Halfpenny take over kicking duties, and his accuracy underpinned a superb Welsh recovery highlighted when North set up Davies' sprint for glory after he smashed Ireland's midfield defence asunder and then found his colleague with a one-handed pass.
But back came Ireland as the lead changed hands for a fourth time inside an hour after Sexton completed his penalty hat-trick to set the scene for an enthralling final quarter.
Wales briefly threatened to unravel when Davies was in the sin-bin, Bowe scoring Ireland's second try 12 minutes from time, but North then powered over in the 76th minute before Halfpenny's clincher.