Rory Best gave Ireland the lead after a mere 47 seconds when he picked up a Brian O'Driscoll blockdown of Stephen Jones' attempted clearance.
Penalties from Jones in the 8th, 17th and 24th minutes put the home side 9-5 in front before Ireland took the lead just before half time with a try from captain O'Driscoll.
It remained like that until the closing ten minutes when man of the match Gordon D'Arcy was stopped just inches from the line but from the ensuing ruck O'Gara mananged to extend an arm to get the crucial touchdown. He added the conversion just for good measure.
Ireland: G Dempsey; A Trimble, B O'Driscoll capt (G Murphy), G D'Arcy, D Hickie (G Murphy 24 min temp); R O'Gara, P Stringer; M Horan, R Best (J Flannery), J Hayes; D O'Callaghan, P O'Connell; S Easterby, D Wallace, D Leamy.
Wales: K Morgan; H Luscombe, J Robinson, J Hook, C Czekaj; S Jones capt, D Peel; G Jenkins, R Thomas, C Horsman; I Gough, A Wyn-Jones; A Popham, M Williams, R Jones.
Referee: Kelvin Deaker (New Zealand).