For the first 50 minutes, Blues were the better side but Ospreys sprung to life to finish with six tries - two each from Hanno Dirksen and Webb, with James King and Sam Underhill also crossing. Dan Biggar converted five to complete his side's scoring.
Gareth Anscombe kicked 17 points for Blues with five penalties and a conversion. Aled Summerhill and Josh Navidi scored their tries.
Tom James was a late withdrawal for Blues, with Tom Isaacs replacing him. James was the fourth Welsh international to be absent from Blues' back division with Rhys Patchell, Alex Cuthbert and Lloyd Williams all missing through injury.
Cardiff Blues maintain European Champions Cup qualification hopes with home win
17/04/2016 AT 16:11
However they overcame these setbacks to take a 10th-minute lead when Anscombe knocked over a straightforward penalty.
Blues had marginally the better of the opening quarter as their pack gained more possession with the visitors conceding a number of penalties for not releasing at the breakdown.
Ospreys also had a couple of chances for kickable penalties but they opted for attacking line-outs. It initially proved the wrong call as some stern defence from the hosts prevented their opponents from capitalising until the 24th minute when Ospreys scored the opening try.
From a scrum 15 metres out from the Cardiff line, King tore away to catch the Blues off-guard and the flanker powered past tackles from Anscombe and Navidi to score the try which Biggar converted.
Blues soon suffered a further blow when Sam Warburton left the field with a shoulder injury but two more penalties from Anscombe gave them a deserved 9-7 interval lead.
Within two minutes of the restart, Blues scored a crucial try. Penetrative runs from Rey Lee-Lo and Dan Fish put Ospreys on the back foot before a well-judged pass from Anscombe created an easy run-in for Summerhill.
Anscombe missed the conversion but he soon kicked his fourth penalty after Ospreys infringed at the scrum. The visitors responded by replacing both props and also introducing Underhill and Josh Matavesi in an attempt to reverse the tide.
The changes paid immediate dividends when Dirksen scored two tries in four minutes.
First an error by Lewis Jones enabled Ospreys to produce their best movement of the match to send Dirksen crashing over in the corner before a wicked bounce evaded Isaacs for the wing to score his second. Biggar converted the second to give his side a 19-17 lead at the end of the third quarter.
It was a remarkable turnaround as Ospreys had looked inferior for most of the match but normality was restored when Navidi beat three defenders to score a splendid individual try and put Blues back in front.
With 10 minutes remaining, rejuvenated Ospreys scored their bonus-point try when Underhill forced his way over from close range with Biggar's conversion giving his side a two-point lead.
Their lock Adam Beard was stretchered off to be replaced by hooker Sam Parry but from the restart he immediately gave away a foolish penalty for Anscombe to nudge his side a point ahead.
But Webb's two late efforts sealed an unlikely victory for the visitors.
Cardiff Blues maintain European Champions Cup qualification hopes with home win
17/04/2016 AT 15:44
Ospreys pile on the points to stay in European Champions Cup hunt
15/04/2016 AT 21:02