Munster needed a 76th minute penalty to sneak past Glasgow 22-20 in the Magners League at Musgrave Park on Saturday.
Glasgow outscored the Magners League leaders by two tries to one, and Ruaridh Jackson's drop goal gave them a 20-19 lead inside the final quarter.
But the Scots had Bernardo Stortoni sin-binned as Munster pummelled the visitors' try-line, and O'Gara mopped up with the match-winning penalty.
Jackson's seventh-minute penalty opened the scoring after O'Gara had a kick charged down and John Hayes was pinged for not rolling away after a tackle.
Munster, who brought Denis Hurley in for the injured Doug Howlett (calf), mounted a swift response.
Paul Warwick attacked with vigour and his kick forward was deflected into the path of Johne Murphy, who was brought to ground close to the Glasgow posts. Richie Gray killed the ball at the ensuing ruck and was promptly yellow carded.
O'Gara tapped over the penalty to level the tie, but Munster could not make use of their numerical advantage.
Jackson missed a kickable penalty from the left, before Munster's forwards began to exert more influence on the half hour, and it took a terrific turnover from Ryan Grant to release the pressure.
Munster's frustration grew as infringements in the scrum and at the breakdown cost them valuable possession and territory, and Glasgow caught them off guard in the 37th minute.
Max Evans broke out of a double tackle near the Munster 22 and although Warwick caught up with him, his well-weighted pass inside was carried on by scrum half Colin Gregor whose fast feet saw him glide in behind the posts for a converted try.
On the stroke of half-time, Munster were pressing for a score when Keith Earls was very harshly sin-binned for not coming through the gate at a ruck.
Munster had got on the wrong side of referee James Jones in the opening half, but they quickly turned the 10-3 interval deficit around.
They stormed out of the blocks for the second half, with O'Gara landing a quick hat-trick of penalties. Referee Jones did little to help the game's flow, drawing the ire of the crowd on a number of occasions.
But he did well to spot Wallace's grounding for his 62nd minute try, following a series of close range surges from his fellow forwards. O'Gara's conversion gave Munster some breathing space at 19-10.
However, Glasgow, hunting for their first away win of the season, had other ideas. Jackson was involved twice and Evans did brilliantly to pass out of the tackle, before the former unleashed DTH van der Merwe for a 65th score.
Gregor stepped in to add the conversion and three minutes later, Jackson followed up with a tidy drop goal. A repeat of the Warriors' 2008 win at this venue was on the cards.
Yet Munster had time on their side and although their try-scoring attempts were thwarted - Stortoni saw yellow for deliberating knocking on, with the hosts about to convert an overlap - O'Gara landed his sixth successful kick from six attempts to keep his side on the winning trail.
The win keeps Munster nine points clear at the top of the table, while Glasgow, who watched Jackson miss a late, long range drop goal, slip to tenth.
Pens: O'Gara 5
Tries: Gregor, van der Merwe
Cons: Jackson, Gregor
Yellow cards: Gray (Glasgow -10th minute);Earls (Munster -40th min); Stortoni (Glasgow -75th min)
Munster: 15 Paul Warwick, 14 Doug Howlett, 13 Keith Earls, 12 L Mafi, 11 Johne Murphy, 10 Ronan O'Gara, 9 Peter Stringer,8 Denis Leamy, 7 David Wallace, 6 James Coughlan, 5 Mick O'Driscoll, 4 Donncha O'Callaghan, 3 John Hayes, 2 Damien Varley, 1 Darragh Hurley.
Replacements: 16 Mike Sherry, 17 Dave Kilcoyne, 18 Peter Borlase, 19 Donnacha Ryan, 20 Niall Ronan, 21 Tomas O'Leary, 22 Sam Tuitupou, 23 Denis Hurley.
Glasgow: 15 Bernardo Stortoni, 14 Alex Dunbar, 13 Max Evans, 12 Peter Murchie, 11 DTH van der Merwe, 10 Ruaridh Jackson, 9 Colin Gregor, 8 Johnnie Beattie, 7 John Barclay, 6 Robert Harley, 5 Alastair Kellock (c), 4 Richie Gray, 3 Moray Low, 2 Dougie Hall, 1 Ryan Grant.
Replacements: 16 Pat MacArthur, 17 Kevin Tkachuk, 18 Jon Welsh, 19 Aly Muldowney, 20 Ryan Wilson, 21 Henry Pyrgos, 22 Dave McCall, 23 Peter Horne
Venue: Musgrave Park
Referee: James Jones