O'Gara kept him nerve to grab victory with the last kick of the game
Ronan O'Gara's last-minute penalty snatched victory for Magners League leaders Munster and left the Ospreys' play-off hopes hanging by a thread.
Munster led 3-10 at half-time after David Wallace's converted try, but the Ospreys went ahead when Alun Wyn Jones' try was soon followed by a penalty try.
Munster responded with two further O'Gara penalties before James Hook's kick looked to have sealed a home win.
But the Ospreys were caught offside and O'Gara's fifth penalty split the posts.
The final whistle followed immediately, leaving the Ospreys to rue a missed opportunity which leaves them in fifth place in the table.
To finish in the top four and secure a play-off place, Scott Johnson's side must collect maxium points against Aironi in their final game of the season and hope Ulster collect no points at the Dragons.
Their other hope, if Ulster win, is for Cardiff Blues to fail to pick up more than three points from their remaining games away to the Scarlets and Dragons.
Munster were already certain to end the season on top of the table, giving them a home sem-final in the end-of-season finale.
But the Irishmen showed their insatiable appetite for victory by pusing the Ospreys until the final seconds at the Liberty Stadium in Swansea.
After a breathless opening 10 minutes, Munster optimistically called for a penalty try for an early tackle on Keith Earls as he went to gather his own grubber kick yards short of the tryline.
But television replays clearly showed that Richard Fussell had timed his challenge perfectly, before Earls knocked the ball on.
The video referee was brought into action moments later as Hook stretched over in the left corner.
No try was again the correct decision, Hook's feet grazing the touchline after a superb covering tackle from Munster scum-half Conor Murray.
The first points came from O'Gara's first penalty, and his clever chip then almost created a try for Lifeimi Mafi, but it was the centre's turn this time to knock on in the process of diving over the tryline.
Lee Byrne's hopes for a fitting farewell party in his final home appearance before joining Clermont Auvergne were ruined when he limped off the field just before the half hour mark.
And three minutes later, the visitors crossed for their only try, with the video referee giving Wallace the benefit of the doubt.
Hooker Damien Varley created the panic with a break from a training-ground move at an attacking lineout, and Wallace then bulldozed his way to the tryline.
James Hook applauds the crowd after his final home game for the Ospreys
Dan Biggar's tackle looked to have held the flanker short, but the video referee judged in Munster's favour despite no clear evidence of the ball being grounded.
O'Gara converted before the home side final got some points on the board four minutes shy of the break with Biggar's penalty.
The home fly-half wasted a simple chance to answer O'Gara's early second-half penalty by dragging his effort wide, the video referee again called into action to make the final decision.
But the Ospreys were right back in the game when Wyn Jones burrowed his way over the Munster tryline after a textbook driving maul.
Biggar converted from the left touchline, taking the home side to within three points at 10-13 down.
A superb Fussell break from his own 22, followed by Rhys Webb's snipping run, almost led to another home try, but a subsequent penalty gave the Ospreys a superb attacking platform.
They opted for a five-metre scrum, and after the Munster pack were penalised once for collapsing, the referee had little hesitation in awarding a penalty try when the visiting front row stood up in unison.
Biggar's conversion put the Ospreys ahead for the first time at 17-13 with 20 minutes to play.
Hook, set to join Perpignan at the end of the season, then looked to have secured a perfect send-off when he slotted over a 35-metre penalty four minutes from time.
Munster were camped in the home 22 for the remaining minutes, but the home fans breathed a huge sigh of relief when O'Gara missed a drop-goal attempt from straight in front.
But Jerry Collins, another playing at the Liberty Stadium for the final time after two years in south Wales, was penalised for a high tackle and sent to the sin bin with the clock nearing 80 minutes.
The infringement gave the visitors a perfect attacking platform, and the over-eager defence was penalised for offside as they charged another O'Gara drop-goal attempt.
The experienced fly-half made no mistake with his kick from in front of the posts to sntach victory with the final kick of the game.
Lee Byrne; Nikki Walker, Tommy Bowe, James Hook, Richard Fussell; Dan Biggar, Rhys Webb; Ryan Bevington, Richard Hibbard, Adam Jones, Ian Gough, Alun Wyn Jones (capt), Justin Tipuric, Marty Holah, Jonathan Thomas.
Huw Bennett, Paul James, Duncan Jones, Ryan Jones, Jerry Collins, Mike Phillips, Andrew Bishop, Sonny Parker.
F Jones; D Howlett, L Mafi, P Warwick, K Earls, R O'Gara (capt), C Murray; M Horan, D Varley, J Hayes; I Nagle, D O'Callaghan; D Ryan, D Wallace, J Coughlan.
M Sherry, W du Preez, T Buckley, T O'Donnell, N Ronan, P Stringer, D Barnes, S Zebo.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.