Ospreys (17) 30
Tries: S Williams, Bowe, Byrne, Bennett. Cons: Biggar 2. Pens: Biggar.
Edinburgh (19) 32
Tries: Cairns 2, Webster, Hamilton. Cons: Paterson 2, Godman. Pens: Paterson 2.
Edinburgh players celebrate after their win at the Ospreys
Edinburgh leapt over the Ospreys into third place in the Magners League with a last-gasp win at the Liberty Stadium.
But the biggest winners of the night were Munster, who now know that one more win should secure them the title.
Second row Jim Hamilton scored the crucial try, burrowing through a ruck to touch down and Phil Godman held his nerve with the conversion.
Ospreys had matched Edinburgh's tally of four tries, but James Hook and Dan Biggar both missed crucial kicks.
In contrast, Edinburgh full-back Chris Patterson had a fine night with the boot - kicking four of his five attempts.
Hugo Southwell had replaced Patterson towards the end, however, and that allowed Godman the glory of kicking the winning two points.
After 10 minutes of their pack softening up the visitors, Ospreys produced two incisive and slick backs moves that suggested the influence of new director of rugby Scott Johnson.
First Biggar's swift pass found James Hook drifting just outside his marker and the centre raced through a gap to send Shane Williams racing over for a try on his 100th Ospreys appearance.
Another try followed from the Ospreys' next attack, Mike Phillips looping around to find Lee Byrne at pace and the full-back handed off Webster to send Tommy Bowe down the touchline.
However, Hook missed both conversions - the first regulation, the second a difficult kick from tight on the right touchline - and the home advantage was only 10-0.
Scrum-half Phillips had already stamped his authority on the game and soon stamped it over opposite number Mike Blair.
The Ospreys nine looked every bit worthy of his Lions selection as he took a quick tap and jinked through the Edinburgh forwards before loping away.
Blair stood in his way but Phillips dipped his shoulder and sent the Edinburgh and Scotland captain cart-wheeling backwards.
With Munster nine Tomas O'Leary desperately unfortunate to have broken his ankle the night before, there is a scrum-half spot open for the Lions.
But Blair's case for inclusion would not have been helped by his rough treatment at the hands of Phillips.
Another man excluded from Ian McGeechan's British and Irish picks was Ryan Jones.
The thought is that the Ospreys and Wales skipper is also foremost among possible reservists should injuries bite in the back-row.
But Jones was too slow to fill his defensive channel after a line-out and Phil Godman raced through the gap to let Ben Cairns finish under the posts, Paterson converting.
Hook and Biggar both missed penalties for the Ospreys, who then had a 'try' by flanker Steve Tandy ruled out by an inconclusive video replay.
Edinburgh then took advantage of a wayward Ospreys line-out close to the home line, the defence caught flat-footed as Cairns crossed for his second try.
Then Godman read the blitz defence to chip over and send Simon Webster cutting back to the try line, Paterson missing the afters this time although he had added to Cairns' scores.
Ospreys did manage to haul themselves back before half-time though, Bowe doing good work out of the tackle to gift a try to Byrne.
Biggar was spot-on with the conversion - the Ospreys' first successful kick of the night - to trim Edinburgh's lead to just 19-17.
Paterson stretched the visitors away again after the restart with two quick goals, the second created by the full-back's break that drew Byrne into conceding a penalty and earned him a yellow card in the process.
Despite being a man light, Ospreys roused themselves and assaulted the Edinburgh line - Ryan Jones now to the fore and leading by example - which ended with hooker Huw Bennett barging over for a bonus point.
Biggar's conversion, going through off the inside of the posts, and two following penalties put Ospreys back into a 30-25 lead with 13 minutes to go.
Edinburgh hammered at the home line as they sought to wrest back the win they thought was theirs, but Ospreys skipper Jones superbly intercepted a pass to raise the siege.
Back came the Scots and the pressure finally told as Hamilton wriggled under a pile of bodies to reach over and tie the scores, Godman holding his nerve to kick the winning conversion.
Ospreys: Lee Byrne; Tommy Bowe, James Hook, Andrew Bishop, Shane Williams; Dan Biggar, Mike Phillips; Paul James, Huw Bennett, Adam Jones, Filipo Levi, Andy Lloyd, Tom Smith, Steve Tandy, Ryan Jones (capt).
Replacements: Ed Shervington, Duncan Jones for James (62), Ian Gough for Lloyd (62), Marty Holah for Tandy (62), Tavis Knoyle, Jonathan Spratt, Jonny Vaughton.
Edinburgh: Chris Paterson; John Houston, Ben Cairns, Nick De Luca, Simon Webster; Phil Godman, Mike Blair (capt); Kyle Traynor, Ross Ford, Geoff Cross, Craig Hamilton, Jim Hamilton, Scott Newlands, Alan MacDonald, Allister Hogg.
Replacements: Andrew Kelly for Ford (65), Ryan Grant for G. Cross (68), Scott MacLeod for C. Hamilton (65), Matt Mustchin for Newlands (41), Greig Laidlaw for M. Blair (74), Andrew Turnbull for Houston (60), Hugo Southwell for Paterson (65).
Referee: Alain Rolland (IRFU).