Having lost to the Glamorgan Wanderers and Ebbw Vale in their last two outings Cardiff were desperate to get back to winning ways, but found themselves trailing 13-3.
Two tries at the start of the second half from Damien Welch and Roger Davies did edge the Blue and Blacks in front before Dan Griffiths kicked the Black and Ambers back into the lead with a penalty. But a grand slam finish, with two Craig Evans penalties, saved the day.
Table toppers Neath maintained their lead as they go in search of their fourth successive title. Their 19-12 home triumph over Cross Keys featured tries from Craig Mitchell and Kevin James.
High flying Ebbw Vale kept up the pressure on the leaders with a 16-12 win at Pontypridd while Bedwas shocked Llanelli 30-15, Glamorgan Wanderers pipped Aberavon 18-15 and Swansea and Llandovery won their basement battles against Bridgend and Maesteg respectively.