Dan Biggar kept the Ospreys in the hunt until the final seconds, while winger Jeff Hassler also scored two opportunistic tries to kept Edinburgh on their toes.
But the reliable boot of South African full-back Carl Bezuidenhout ensured Edinburgh were never headed, securing their first win in four with a 16-point haul of his own.
Edinburgh looked lively from the start, winning a penalty after Dougie Fife was taken out in the air and kicking upfield only for Geoff Cross' offload to be adjudged forward in a promising position.
But it was the visitors who got the first points on the board, a slick passing move and some incisive offloading buying winger Hassler the room to scorch over.
Biggar's conversion drifted wide as the Ospreys took a 5-0 lead on six minutes, with the Welsh side hoping to claim a first RaboDirect PRO12 win in Scotland since February 2012.
The lead didn't last long, prop Wicus Blaauw winning a scrum penalty that Edinburgh kicked upfield for a line out on the ten-metre line.
From the set piece the Edinburgh pack found some momentum and drove forward to the 22 where scrum-half Hart took control, breaking away with lightning speed to level the scores.
Bezuidenhout added the extras to give the home side the lead and Edinburgh continued to press, winning another penalty at scrum time. Bezuidenhout stepped up to send over a booming penalty on 15 minutes and increase Edinburgh's lead to 10-5.
The Ospreys fought back, camping in the Edinburgh half, but repeated penalties kicked to the corner failed to force a breach in the home side's defence.
And on 26 minutes they extended their lead further, Jack Cuthbert leading a great breakout from defence. He danced past his man, fending off another would-be tackler and slipped the ball to centre Beard who ran a lovely line in support to outpace the defence and touch down in the corner.
Bezuidenhout's conversion from the touchline came off the post, and 13 minutes from the break Edinburgh led 15-5.
Keeping the Ospreys at bay at the other end was proving tough, however, with Cross sent to the sin bin for not releasing in the tackle. Biggar sent the resulting penalty through the posts to reduce the deficit to 15-8 with ten minutes to the interval.
Edinburgh looked to have the edge on their opponents upfront despite being a man light, and six minutes before the break it was Hart to the fore again.
The forwards battered their way downfield from where Hart caught the Ospreys defence napping again to sneak over the line. Bezuidenhout's conversion from out wide this time found its mark and it was 22-8 with four minutes to the break.
Edinburgh did cough up a penalty at the scrum, which Biggar converted to reduce the deficit by three points before the sides disappeared down the tunnel for half-time.
It was the Ospreys who drew first blood upon the restart, Biggar taking advantage of another infringement at the breakdown to slot a penalty and make it 22-14.
And they continued to press, forcing another three-pointer in the tackle and Biggar made it a five-point game with 26 minutes still left to play. But the boot of Bezuidenhout knocked over a penalty for the home side to give Edinburgh a little breathing space on 58 minutes.
And just three minutes later that was gobbled up by Hassler who raced onto a grubber kick and dived over the line, with the try awarded after a long hard look from the TMO. Biggar's conversion was wayward and with a quarter of the game to go there were only three points in it.
Another booming Bezuidenhout penalty restored the six-point gap and then Andries Strauss nearly sealed it for Edinburgh, only to be pulled down just inches from the try line.
Ashley Beck was sent to the sin bin for his part in stopping Strauss barrelling forward, and Bezuidenhout made no mistake with the resulting penalty to increase the lead to 31-22 with time running out.
But seconds later Ollie Atkins was also sent to cool his heels on the side of the pitch and Biggar's penalty brought the Ospreys back into contention.
Yet despite their efforts the Welsh side couldn't force their way past Edinburgh and had to settle for a losing bonus point on the night, the home side arresting their recent slump in form with a first win in four RaboDirect PRO12 games.
|Edinburgh Rugby Score Card|
|Ospreys Score Card|