Ireland’s 22-17 victory meant that Wales were beaten in Cardiff for the first time since November 2017.
Ireland, crushed 57-15 by England seven days ago, bossed most critical areas ahead of next Saturday’s return game in Dublin.
Fly-half Jack Carty added a conversion and penalty for the visitors, while his opposite number Jarrod Evans kicked a penalty before going off at half-time and being replaced by Rhys Patchell, with a second-half penalty try sealing Wales’ fate.
Wales finished strongly, with debutant wing Owen Lane and Patchell claiming late tries and Patchell converting both, but it was not enough.
Gatland names his 31-man World Cup squad on Sunday, yet only Lane and Patchell made strong claims for any of the few remaining places.
Ireland boss Joe Schmidt, though, will have been encouraged by his team’s recovery powers following a shambolic effort at Twickenham when England crushed them under an eight-try onslaught.
Stockdale, who departed at the interval, Carty, centre Bundee Aki, skipper Peter O’Mahony and his fellow flanker Tadhg Beirne were among those that impressed.
Ireland needed to make a confident start following their Twickenham torture and they edged the initial forward battle before Carty kicked a ninth-minute penalty.
Wales, in contrast, experienced an error-strewn opening that was highlighted by centre Owen Watkin dropping a pass in open play under no pressure.
Evans, though, settled quickly on his final World Cup audition, showing some neat touches and freeing Lane following a cleverly-placed kick.
He also opened Wales’ account through a short-range penalty that cancelled out Carty’s strike as the home side began to show continuity.
But Wales were then rocked by a spectacular Ireland breakaway try that had its origins in a powerful surge by prop Dave Kilcoyne.
Andrew Conway then caused further stress in the Welsh defence on a lengthy weaving run before he delivered a scoring pass to Stockdale, who collected his 15th try in 21 Tests.
Carty kicked the conversion for a 10-3 lead before Evans missed a penalty chance from in front of the posts and Ireland immediately punished another Wales blunder.
Flanker Aaron Shingler was the culprit on this occasion, throwing out a one-handed pass that none of his colleagues could gather, and Stockdale kicked ahead before gathering a kind bounce and finishing impressively.
Carty could not add the extras but alarm bells were sounding in the Wales camp, 12 points adrift at half-time and showing little consistent sign of troubling Ireland’s defence.
Gatland made three substitutions for the second period, sending on Patchell for Evans and taking off both props – Rhys Carre and Samson Lee – with Rob Evans and Leon Brown replacing them.
Brown was sin-binned by referee Romain Poite for a scrummaging offence just 11 minutes after going on and Ireland enjoyed territorial dominance through a powerful set-piece.
Ireland blew a scoring chance when Carty’s pass to Conway was ruled forward but Poite awarded them a penalty try, opening up a 19-point advantage.
Wales belatedly stirred when Lane finished impressively for a try 16 minutes from time and Patchell crossed late on but Ireland had done enough.