Edinburgh's character-building win - their first in the league since beating Glasgow Warriors on January 2 - comes just over a week after they confirmed Murrayfield as their home ground for at least the next five years.
Dan Biggar looked all too comfortable at the home of Scottish rugby when his try, conversion and two penalties opened up an early 13-3 lead for the Ospreys.
But tries from Jim Thompson and Tim Visser hauled Edinburgh back into the game. Greig Laidlaw also had an important kicking contribution of two penalties and two conversions as the Scots moved above Benetton Treviso into ninth in the table.
The in-form Ospreys, who are now third in the table, had several Wales internationals back on duty after the Six Nations.
The visitors made a fast start and their first foray into home territory yielded a penalty which fly-half Biggar steered between the posts to set the scoreboard ticking.
He doubled his tally three minutes later before Edinburgh clawed back three points when Laidlaw stroked over a penalty.
The scrappy nature of the contest ensured that neither side was able to establish any dominance but it was the Ospreys who looked the more threatening with ball in hand.
They extended their advantage when Richard Fussell darted down the right flank and flipped the ball inside to Biggar who dotted down, adding the conversion to carve out a 10-point lead.
Edinburgh thought they had reduced the deficit when man-of-the-match David Denton plunged over after a slick handling move, but television match official Jim Yuille ruled that the number 8 had knocked on as he stretched for the line.
That close call sparked a flurry of attacks by the home side but their efforts were undone by a lack of inspiration and a solid defensive effort by Ospreys.
Big winger Nikki Walker, who scores for Scotland at this venue last Saturday, was fortunate to avoid a visit to the sin-bin for a high tackle on Ben Cairns.
Then, after more than 20 minutes of almost unrelenting pressure, Edinburgh finally made the breakthrough.
After a series of drives, the ball was spun wide to Cairns who sent Thompson in at the corner with 35 minutes on the clock. Laidlaw thumped over the touchline conversion to reduce the arrears to 13-10 at half-time.
The Ospreys made a lively start to the second half but failed to add to their points tally and Nick Scrivener's side restored parity when Laidlaw booted another penalty.
Almost immediately, Biggar had an opportunity to respond in kind but pushed his kick wide of the target.
However, he quickly atoned for that miss to make it 16-13 in his side's favour. The penalty was awarded following an offence that earned Edinburgh lock Esteban Lozada a yellow card.
Edinburgh's response was a typically eye-catching run by Visser and although the league's top try scorer was thwarted, he made no mistake at the next time of asking.
The big Dutchman dodged past Rhys Webb and Tommy Bowe before twisting over the line for his 12th try of the campaign. Laidlaw added the extras to give his side a sudden four-point cushion.
The Ospreys management reacted by emptying their bench in an attempt to turn the match around. However, the changes failed to produce a change in fortunes and Edinburgh made sure of the win when Laidlaw slotted his successful third penalty of the night.
Acknowleding that the hosts deserved their victory, Ospreys forwards coach Jonathan Humphreys said: "Edinburgh were by far the better team. It was very frustrating to watch, from our point of view.
"Edinburgh were the ones that brought the intensity to the game, that's the most disappointing thing. I thought they played very well as a team while we were more about individuals.
"That meant we lost our attacking shape and we didn't look threatening at all, all night. It's nothing to do with the internationals returning.
"The majority of the boys that started this game were the ones that have been with us throughout February and March, and they are the ones that will be most disappointed with the performance.
"We're still very much in this race though. Munster have pulled away a bit now but there is everything to play for and the last four is in our own hands, so we need to bounce back from this disappointment positively and not get carried away."
|Edinburgh Rugby Score Card|
|Ospreys Score Card|