Rhys Patchell and Aled Summerhill crossed the line in the 74th and 78th minutes to wrap up the win, allowing the Welsh side to clinch what had been a tight contest.
Fourth-placed Ulster drew first blood, Paddy Jackson splitting the posts with a 32nd-minute penalty.
Jackson then put his men six points ahead after Cardiff failed to release in the tackle.
With two defeats in succession before this against their name, Cardiff needed to get going, and Patchell started them up with a penalty on the stroke of half-time.
Another long-ranger from Patchell got them level three minutes after the break, but Ulster then went over the line with the game’s first try.
Ulster turned down a shot at goal with a penalty, Franco van der Merwe running the ball, Sam Arnold taking it on and then feeding Craig Gilroy who dotted down.
Jackson converted, but Patchell replied with a third penalty to keep Cardiff in touch.
And that platform bore fruit in the closing stages.
Reynold Lee-Lo broke the line and passed to the supporting Patchell who was able to crown a fine individual show with a five-pointer, upgrading it with a conversion. And then, to seal the deal, quick hands across the line let in Summerhill who rounded things off, with Patchell again converting for a personal haul of 18 points as Cardiff picked up their sixth win of the season.
Tries: Patchell, Summerhill. Cons: Patchell 2. Pens: Patchell 3.
Fish, Scully, Summerhill, Lee-Lo, James, Patchell, T. Williams, Thyer, Rees, Ma’afu, Hoeata, Down, Turnbull, E. Jenkins, Vosawai.
J. Evans for Fish (59), Jones for T. Williams (65), T. Davies for Thyer (74), Dacey for Rees (67), Filise for Ma’afu (41), Cook for Hoeata (74), Navidi for Vosawai (61).
Tries: Gilroy. Cons: Jackson. Pens: Jackson 2.
Olding, Gilroy, L. Marshall, Arnold, Stockdale, Jackson, Pienaar, Black, Andrew, B. Ross, Browne, van der Merwe, Diack, Henry, Williams.
Cave for L. Marshall (6), Scholes for Arnold (69), P. Marshall for Pienaar (78), McCall for Black (48), Lutton for B. Ross (41), Wilson for van der Merwe (65), Reidy for Henry (55).
John Lacey (Ireland).