Full-back Halfpenny kicked an 80th-minute penalty after Ireland flanker Stephen Ferris was sin-binned for a dangerous tackle on Wales lock Ian Evans.
It appeared a harsh call by English referee Wayne Barnes, with the offence nowhere near as bad as Bradley Davies' tackle which earlier upended Irish replacement Donnacha Ryan. Davies received a yellow card, when it should have been red.
Halfpenny held his nerve to give Wales a rare Six Nations win in Dublin 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 Leigh 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 dramatic clincher.
Gilbert has released a new line of rugby cleats. The Gilbert Virtuo 8S is part of the exciting new product. Check it out.
The entire All Blacks apparel line has been updated for 2013/14. Check out the New Zealand All Blacks polo.
The Nike Tiempo is a solid rugby cleat and one of few styles still made from full-grain natural leather.
The Gilbert Blitz 8S rugby cleat is a great cleat at a great price of $69.99. Get a new pair of cleats today.
A cool looking all black rugby cleat with the high performance adidas is known for. Get in the Gear!
Wear the crest of the British and Irish Lions on your t-shirt. A great look for the summer.
The All Blacks Performance t-shirt is black with hints of blue from the training jersey. Very Cool.
The New Zealand All Blacks training jersey for 2013/14. Get in the Gear!
The USA Rugby Pro Alternate rugby jersey is perfect for any fan of the Eagles. Get yours to wear during the summer Test matches.
The NEW All Blacks 2013/14 jersey has arrived at World Rugby Shop. Dare to wear the colors of the All Blacks.