Ulster's Trimble was sin-binned for a high tackle but also scored
Blues 20 (10)
Tries: Czekaj, Shanklin.
Cons: Blair, Macleod.
Ulster 17 (3)
Tries: Wilson, Trimble.
Cons: Steinmetz 2.
Nick Macleod dropped a last-gasp goal to keep Cardiff Blues' hopes of a Magners League title alive and dent those of defending champions Ulster.
It seemed as though Ulster had grabbed a precious away win when Andrew Trimble scored from a Blues handling error.
But Tom Shanklin's try drew the Welsh level before Macleod, having missed two, struck his third drop-kick over.
Chris Czekaj grabbed an opening try for the Blues, with Roger Wilson replying for Ulster before the frantic end.
Blues full-back Ben Blair and rival kicker Paul Steinmetz both missed their first attempts at the posts in a lukewarm opening period.
The Ulster centre, taking the kicking duties in the injury-enforced absence of David Humphreys, was the first to break his duck, putting the visitors into a 3-0 lead.
But the defending Magners League champions soon lost their early advantage when Trimble was sin-binned for a high tackle on Blair.
Blair struck the resulting penalty to level things after 19 minutes, signalling a sustained period of pressure by the Blues.
Ulster defender manfully and held out until they were back to full strength, but were unable to get back on the front foot.
Eventually the Welsh made their possession pay as fly-half Macleod found a gap to dart through and send Czekaj loping away towards the try line.
Trimble came covering across but he was muscled off by the big wing, who kept his legs pumping and - with a helping shunt from Jamie Robinson - forced his way over.
Blair's conversion gave the Blues a 10-3 lead at the break, but the home side should have stretched their lead soon after the restart.
A series of drives created a two-man overlap on the right, but a combination of Andy Powell's casual pass and Rhys Williams' butter-fingers saw the ball dropped with the line begging.
Ulster upped the tempo and the Blues were forced to defend frantically as the Irishmen turned the screw.
Eventually the pressure told and number eight Wilson charged through for a converted try to level the match.
The Blues showed signs of recovery but, just as they have so many times this season, gifted the opposition a try as their passing in midfield broke down.
Steinmetz seized on the loose ball, hacking on before gathering to send Trimble away under the posts for a seven-pointer.
Blair hit the post with a penalty but then Czekaj produced a crucial break to let Shanklin, on from the bench, show his strength to just touch down.
Macleod took on the kicking duties to stroke the conversion over and level the scores, ushering in a breathless last few minutes dominated by the Blues fly-half's boot.
First he had an attempted clearance charged down, only for the bouncing ball to beat the chasing Ulster players to the Blues' dead-ball line.
Macleod was then wide with two drop-goal attempts, before finding the target with his third attempt in the last few seconds of injury time to snatch the win.
The Blues are now seven points behind leaders Leinster but with a game in hand, while Ulster remain four behind their Irish rivals having played 18 games to Leinster's 17.
Ulster coach Mark McCall:
"I am very proud of the performance we gave and although we made some mistakes, we can be happy with our commitment, spirit and how we put our bodies on the line.
"That is the best we have played since October and we can hold our heads high.
"We played fantastically well in the second half but just made some unenforced errors in our own territory.
"Our challenge for the title is over but we want to finish the season with two big performances at Ravenhill."
Blues: Ben Blair; Rhys Williams, Jamie Robinson, Marc Stcherbina, Chris Czekaj; Nick Macleod, Mike Phillips; Gethin Jenkins, T Rhys Thomas, Taufa'ao Filise, Bradley Davies, Robert Sidoli, Andy Powell, Martyn Williams, Xavier Rush (capt).
Replacements: Gary Powell for Filise (62), Gareth Williams, Deiniol Jones for Davies (64), Mark Lewis, Ed Fairhurst, Nicky Robinson, Tom Shanklin for Stcherbina (66).
Ulster: B Cunningham; T Bowe, A Trimble, P Steinmetz, A Maxwell; P Wallace, I Boss; B Young, P Shields, S Best (capt), J Harrison, R Caldwell; S Ferris, N Best, R Wilson.
Replacements: N Brady, J Fitzpatrick, T Barker for Caldwell (79), N McMillan for Ferris (72), K Campbell for Boss (64), K Maggs, P McKenzie.
Referee: David Rose (RFU).