Wales’ capital region led 9-7 at half-time and took a major stride towards victory when Aled Summerhill raced over.
But two quick-fire tries from Hanno Dirksen blew the game wide open before Josh Navidi responded.
Anscombe kept the scoreboard ticking following a try from Sam Underhill but Rhys Webb sniped over for a brace in the closing stages to take the derby spoils.
The defeat all but ends Cardiff Blues’ hopes of a top six finish to the league season but they will be determined to finish the season on a high against Edinburgh next Saturday.
The Swansea-based region made a strong start at the Principality Stadium and enjoyed the early territory and possession.
But Wilson’s side soaked up the pressure and Gareth Anscombe booted them into the lead with a penalty on six minutes.
The Ospreys remained in the ascendant but the Blues back-row were on top at the breakdown and winning penalties and turnovers.
However they went behind on 24 minutes when James King powered over a five-metre scrum with Dan Biggar converting for a 7-3 lead.
That however sparked the Blues into life with Tom Isaacs, an 11th hour replacement for Tom James, making a fine break.
He could not find the necessary support to give a try-scoring pass but possession was maintained with Josh Turnnbull and Ellis Jenkins making yards.
The ball was spread to the right wing with Garyn Smith tackled into touch but minutes later they secured a kickable penalty, which Anscombe slotted.
And the Wales international booted the hosts into the lead on 37 minutes after Taufa’ao Filise earned a scrum penalty.
Cardiff Blues made a flying start to the second-half with Dan Fish’s electric break laying the platform.
They went through the phases before Anscombe fired a flat miss-pass to put Summerhill over in the corner.
Anscombe failed to add the extras but the try had given them a 14-7 lead and he soon added a penalty.
However the Ospreys clawed their way back and then took the lead thanks to two tries in five minutes from Hanno Dirksen.
First he was released by an audacious through the legs pass from Rynier Bernardo and then a fortuitous bounce went away from Isaacs and into the hands of Owen Watkin, who gave the try-scoring pass.
Biggar converted the latter to give the visitors a two-point lead but Wales’ Capital Region responded emphatically.
There was a fear the Blues were playing too much rugby as they offloaded out of contact in their own half but they consistently made ground.
A half break from Isaacs made the initial inroads and both Dan Fish and Tomos Williams were involved in the build up before Navidi beat several defenders to rampage over.
Anscombe converted to give his side a 24-19 lead just after the hour mark but the thrilling encounter continued to swing.
The Blues were unable to close the game out and the Ospreys kicked a penalty to the corner.
They were initially held at bay but two phases later Rhys Webb delayed his pass perfectly to send Sam Underhill through a hole.
Biggar made the simply conversion to give the visitors a 26-24 lead with less than ten minutes to spare.
Anscombe instantly responded to reclaim the advantage after the Ospreys were penalised for blocking at the restart.
But the topsy-turvy nature of the encounter continued as the Ospreys worked their way downfield and Rhys Webb dived over a ruck to touch down in the corner.
And as Wilson’s side battled at the death, Webb claimed a second to rub salt into the wounds.
Cardiff Blues: 15 Dan Fish, 14 Aled Summerhill, 13 Garyn Smith, 12 Rey Lee-Lo, 11 Tom Isaacs (Evans 76), 10 Gareth Anscombe, 9 Lewis Jones (Williams 56); 1 Gethin Jenkins (c) (Thyer 65), 2 Matthew Rees (Dacey 54), 3 Taufa’ao Filise (Lewis 65), 4 Josh Turnbull, 5 James Down, 6 Sam Warburton (Hoeata 28, Vosawai 59), 7 Ellis Jenkins, 8 Josh Navidi
Replacements: 16 Kristian Dacey, 17 Brad Thyer, 18 Dillon Lewis, 19 Jarrad Hoeata, 20 Manoa Vosawai, 21 Tomos Williams, 22 Jarrod Evans, 23 Gavin Evans
3-0 – Penalty (Anscombe, 6 minutes)
3-7 – Try (King, 24 minutes), Con (Biggar, 24 minutes)
6-7 – Penalty (Anscombe, 30 minutes)
9-7 – Penalty (Anscombe, 37 minutes)
14-7 – Try (Summerhill, 42)
17-7 – Pen (Anscombe, 49)
17-12 – Try (Dirksen, 54)
17-19 – Try (Dirksen, 59), Con (Biggar, 59)
24-19 – Try (Navidi, 62), Con (Anscombe, 63)
24-26 – Try (Underhill, 70), Con (Biggar, 71)
27-26 – Pen (Anscombe, 72)
27-33 – Try (Webb, 75), Con (Biggar, 76)
27-40 – Try (Webb, 79), Con (Biggar, 79)