Joe Schmidt’s men matched the Ireland record of 10 consecutive Test victories, spoiling Warren Gatland’s 100th game in charge of Wales and all but ending its hopes of winning the title.
Injury-hit Ireland outscored its opponents by five tries to three, Stockdale going over early on and Bundee Aki crossing on the stroke of halftime after a Gareth Davies try and the boot of the fit-again Leigh Halfpenny had edged Wales in front.
LIVE STREAM: Watch Six Nations on DAZN
Dan Leavy and Cian Healy touched down as Wales were outmuscled by the rampant Ireland forwards, but Wales was back in it midway through the second half courtesy of an Aaron Shingler try that was superbly converted by Halfpenny.
Steff Evans set up a tense finale with a third Wales try in the closing stages following a three-pointer from Conor Murray, who took over kicking duties after Jonathan Sexton missed two penalties and as many conversion attempts on an off day for the fly-half.
Stockdale sealed it with a breakaway try right at the end in a dramatic climax to a pulsating encounter as Ireland made it three wins out of three in the tournament.
Halfpenny marked his return by sending a penalty through the posts just two minutes in. Sexton missed an opportunity to level from the tee soon after when he struck a post, but he made amends by playing a key role in an early Ireland try.
The fly-half took a pass from Murray and whipped a sumptuous ball out to Stockdale, who claimed a seventh try in as many Tests with a simple finish in the left corner with seven minutes on the clock.
Sexton failed to convert and uncharacteristically missed another straightforward penalty before Wales scored their first try from out of the blue, the nippy Davies changing direction sharply and darting through a gap to go over following a strong run from Shingler midway through the first half.
Halfpenny added the extras and was on target with a penalty as Wales’ kicking game worked a treat, but Sexton got off the mark from close range and converted to edge his side in front at 15-13 after Aki reached out to dot down when the Ireland forwards applied immense pressure.
Ireland carried on where it left off early in the second half, Leavy powering his way over and Healy also touching down from close range following a turnover at the lineout.
Sexton was unable to convert both scores, but Ireland looked to be in control with Chris Farrell outstanding in his Six Nations debut until Evans scooted away down the right and Shingler was on hand to score a second Wales try that Halfpenny converted superbly.
Gatland’s men were not finished yet, though, Scott Williams and Josh Navidi combining before Evans was given the opportunity to run in for a third Wales try that the reliable Halfpenny converted to make it a three-point game with three minutes to play.
But there was huge relief for the vast majority of a partisan crowd when the rapid Stockdale plucked a stray pass to race away and go under the posts, Joey Carbery converting right at the end of a breathless encounter.