The Barbarians held on to a 23-29 lead to beat Ireland despite a sustained late period of attack from Ireland at Thomond Park.
The Barbarians fell 36-25 to England last weekend at Twickenham but took their game to Ireland in the first half which effectively won the match for the visitors.
Ireland were playing an understrength team ahead of their tour to New Zealand and Australia.
Early tries by Xavier Rush and George Smith put the Baabaas in control at 3-21 but then Niall Ronan scored for Ireland and after the conversion the teams went in for half time with Ireland trailing 10-21.
Cedric Heymans scored the Baabaas third try after the break and Tony Buckley responded for Ireland and O'Gara who had converted both Ireland's tries added another two penalties to bring his points tally to 13 for the match.
Final Score Ireland 23 (10) Barbarians 29 (21)
Scorers
Ireland
Tries - Ronan, Buckley
Pen - O'Gara 3
Con - O'Gara 2
Drop -
Barbarians
Tries - Rush, Smith, Heymans
Pen - James 3, Elissalde
Con - James
Drop -
Referee: Romain Poite (France)
Teams
Ireland: Kearney, J. Murphy, Duffy, McFadden, Trimble, O'Gara, Stringer, Horan, Cronin, Buckley, O'Donoghue, Tuohy, Muldoon, Ronan, Henry.
Replacements: Bowe , D Wallace , O'Leary, Court , Flannery , M. O'Driscoll O'Callaghan .
Barbarians: Warwick, Heymans, Laulala, Rabeni, D. Smith, James, Mignoni, Barnes, Brits, Johnston, Thion, O'Kelly, Quinlan, G. Smith, Rush.
Replacements: Estebanez, Elissalde , Kelleher, White , August, So'oialo , Williams .