But a late Dan Biggar penalty meant the Ospreys moved back into fourth place in the table ahead of Welsh rivals the Scarlets on points difference.
The Ospreys started the game with intent, a powerful scrum opening up gaps in the middle of the field through which Jonathan Thomas was able to attack Cardiff fly-half Rhys Patchell's channel and make big gains as Cardiff desperately funnelled back in defence.
But a fantastic break down the left led by Cardiff's Gavin Evans ended with the ball flicked inside to Leigh Halfpenny who crossed for the first try of the game on six minutes.
Halfpenny converted his own score to give the Blues a 7-0 lead, although that was immediately eroded by a Dan Biggar penalty that got the Ospreys on the scoreboard from wide out.
But the Ospreys suffered a setback when international lock Ian Evans departed with quarter of the game gone after a bang on the hip to be replaced by Joe Bearman.
With Justin Tipuric in full flow the Ospreys looked to attack, Tipuric nearly crashing over only to be repelled at close quarters.
The ball was recycled and James King steamed over out wide to touch down near the posts and put the Ospreys ahead for the first time. Dan Biggar's conversion made it 10-7 and took the Wales fly-half to 898 league points.
Halfpenny kept Cardiff in the game with his first penalty of the evening to level the scores at 10-10, but Biggar restored the three point gap with a shot at goal of his own shortly after.
Seven minutes before the break the Ospreys scored their second try of the game, with Tipuric to the fore again. The flanker made a powerful surge forward before the ball was moved through the hands to Spratt who shrugged off the attempted tackle of Patchell to cross the whitewash.
Biggar's conversion made it 20-10 at the interval and sent the Ospreys in at half-time in the second game of Judgement Day dreaming of a bonus point.
But the introduction of prop Taufa'ao Filise from the bench at the start of the second period changed the complexion of the match, with Cardiff exerting much more pressure at the set-piece.
One rumbling drive forward took Cardiff to the Ospreys 22 and the penalty inevitably followed, with Halfpenny dispatching the shot with ease.
The swing in momentum seemed to disrupt the Ospreys who struggled to get any go forward as the game reached 60 minutes.
However, Cardiff lost influential scrum-half Lloyd Williams to injury going into the final quarter shortly Halfpenny struck another penalty to reduce the deficit to just four points at 20-16 to keep the Blues in the hunt.
And the pressure seemed to get to Biggar who snatched at an easy penalty chance as the Ospreys struggled to get on the scoreboard in the second half.
But a high kick to Alun Wyn Jones found the lock on the wing and he in turn passed to Spratt whose bullocking run took the Ospreys deep into the Cardiff 22 only for Scott Baldwin to knock on a bullet pass from Biggar five metres out.
But with the clock ticking away the Ospreys expertly kept play in the Cardiff area forcing a series of attacking scrums before Biggar kicked a late penalty to win the game.
|Cardiff Blues Score Card|
|Ospreys Score Card|