Alan MacDonald scored a last-gasp try to clinch a hard-earned win for Edinburgh at the Liberty Stadium.
James Hook had looked to have kicked the Ospreys into next season's Heineken Cup scoring all of their points.
The hosts twice came from behind after conceding tries at the start of each half, the first from Allister Hogg.
And Nick De Luca's try at the second-half re-start was overturned by the boot of Hook before MacDonald clinched the win at the death.
Cannot play media. Sorry, this media is not available in your territory.
Advertisement
Highlights: Ospreys 18-19 Edinburgh
Edinburgh captain Hogg opened the scoring with the first try of the evening after just eight minutes.
He finished off a fine move by the visitors driving just over the line with Calum MacRae converting.
Hook reduced the deficit two minutes later from a penalty before MacRae wasted a chance to restore a seven point advantage soon after.
Both defences holding up in a game that had an end-of-season feel to it.
But Hook was on hand again midway through the first half as the Ospreys slowly clawed their way back into the game.
And he put them 12-7 in front before the break after adding two more successful kicks.
Edinburgh were reduced to 14 men in the closing stages when Hogg was yellow-carded for failing to roll away.
The Ospreys' were lucky not to be down to 14 themselves when Justin Marshall escaped punishment for putting a foot in during the same incident.
The visitors started the second half as they did the first - with a try.
De Luca started a fine move breaking from an Ospreys re-start and was on hand at the end of it to go under the posts.
MacRae restored the lead for Edinburgh with his conversion.
But no sooner were the visitors back up to a full compliment of players, they were a man down again.
Prop Geoff Cross was sin-binned for bringing down a maul and Hook put the Ospreys back in front with another perfect kick.
He then added his sixth penalty with 12 minutes to go of a scrappy second half, but Edinburgh never looked out of it.
And four minutes into overtime, they got their reward.
Persistent pressure paid off as Edinburgh kept the ball alive for MacDonald to cross in the corner.
The conversion was unsuccessful, but that did not matter for the visitors and the win was secured, leaving the Ospreys stunned.
"I thought we played pretty well tonight," said Edinburgh head coach Andy Robinson.
"We scored two very good tries, one at the start at the first half, and one in the second, and I was very pleased with the ambition we played with. And to finish it off in injury time was tremendous."
Ospreys coach Lyn Jones said: "It's always disappointing to lose games, especially at home.
"We wanted to finish a very good season off on a high and thank the supporters but it wasn't to be.
"We didn't play well, made unforced errors and made mistakes we don't do from week to week.
"They took us on and are the first team to come to the Liberty this year in the Magners League and attempt to play rugby."
Ospreys: Byrne, Brew, Parker, A. Bishop, Vaughton, Hook, Marshall, D. Jones, Bennett, Griffiths, Wyn-Jones, Evans, J. Thomas, Holah, R. Jones. Replacements: Connor for Parker (77), Spratt for A. Bishop (55), Webb for Marshall (80), Hibbard for Bennett (70), A. Jones for Griffiths (65), Gough for Wyn-Jones (74), Tiatia for J. Thomas (65).
Edinburgh: MacRae, Turnbull, Cairns, De Luca, Maxwell, Godman, M. Blair, Allori, Ford, G. Cross, Mustchin, Gissing, Hogg, MacDonald, Callam. Replacements: D. Blair for Godman (62), Laidlaw for M. Blair (59), Lawrie for Ford (80), Traynor for MacDonald (57). Not Used: Pringle, Newlands, Dey.
Bookmark with:
What are these?