Ireland's impressive home record was at risk after losing Lions Tadhg Furlong, Iain Henderson, and Robbie Henshaw after the routine win over Italy, and Wales welcomed back a Lions trio of Leigh Halfpenny, Dan Biggar, and Liam Williams.
But Ireland lost nothing in its ball-control game, and scored its first try of five after a Jonathan Sexton penalty hit the post.
Wales ran it but Scott Williams threw a forward pass. Still in the Welsh 22, Ireland ground through the phases until bullet passes by Conor Murray and Sexton gave an unmarked Stockdale a free run in on the left wing.
Sexton missed his first three goalkicks and was turned over but Ireland's grip looked firm — until Wales flanker Aaron Shingler split the defense and scrumhalf Gareth Davies pouched a loose pass and darted over.
Halfpenny converted, added a 40-meter penalty, and Wales, against all the statistics, led 13-8 close to halftime.
But Ireland practice multiple phases with time running down. They launched another and, as the clocked ticked into the 42nd minute of the half, center Bundee Aki reached out to score.
Sexton's conversion gave Ireland a deserved lead at the break, but only by 15-13. Wales, despite making 101 tackles to Ireland's 30 and conceding six penalties, was handling the pressure.
Ireland finally imposed itself in the third quarter. Flanker Dan Leavy ended 11 phases by barging over with a Sexton push.
Then Wales No. 8 Ross Moriarty was caught in-goal, and Ireland prop Cian Healy burrowed under three defenders to score in the right corner for the bonus-point fourth try, the most Ireland has scored against Wales in 14 years.
At 14 points behind, Wales sent on reinforcements, finally saw some ball, and opened up.
Biggar outjumped Rob Kearney, Wales spread the ball left then right, and Shingler received an overlap to touch down.
Sexton declined an easy penalty kick for a quick tap instead, but the move died from a knock on and he was replaced.
Murray kicked a penalty for 30-20 and it seemed game over.
Next minute, Wales wing Steff Evans was scoring a try. Williams offloaded to Josh Navidi, who drew the last man. Halfpenny converted, the gap was cut to three, and Wales went all out.Until Stockdale plucked a pass out of the air and relieved the Irish.