They thought they had pulled off an unlikely win when Stephen Jones put over a long-range drop goal in the first minute of stoppage time to edge his side 24-22 in front but, in an epic finale, Irish replacement Ronan O'Gara replied in kind.
And winger Denis Hickie charged down Jones' last attempt at a drop goal to settle a dramatic match, which provided Ireland with their 10th straight win.
Eddie O'Sullivan's men were far from at their fluent best but they will take on Clive Woodward's men in Dublin next week in buoyant mood.
Wales, who need to beat France in Paris next Saturday if they are to salvage their disappointing season, at least restored their pride with a tremendous performance that turned the table upside down.
They stunned Ireland with a try from man of the match Stephen Jones after 15 minutes and scored two more after the break through Martyn Williams and Gareth Thomas.
Jones converted all three tries but missed two penalties whereas David Humphreys crucially landed all four of his penalty kicks, even though he was unable to convert Keith Gleeson's brace of tries either side of half-time.