Blues blazed into a 9-0 lead courtesy of Rhys Patchell and Halfpenny before a crucial moment on the half hour.
Visiting wing Will Harries scored a try and Patchell limped off, after being injured in the build-up, as Dragons edged into a 10-9 lead at the break.
Former Blue Jason Tovey kicked Dragons further ahead but a superb final half hour from the home pack created a platform for Halfpenny - plus a superb drop goal from Gareth Davies - to kick the home side to derby day success.
A big early scrum gave Blues a free kick and field position with Patchell kicking in behind to force Dragons to play from deep inside their own 22. But the visitors held firm and caused problems on the home lineout in the opening minutes.
Dragons first attack saw Blues rattle into tackles to force a knock on as Josh Navidi countered and freed up space for Patchell to punt into touch.
A low clearing kick from Jason Tovey was run back with interest by Halfpenny at full tilt and when Dragons failed to release in the tackle the penalty was awarded. Patchell took over kicking duties, with Halfpenny having treatment, and he made no mistake.
Alex Cuthbert latched onto Patchel’s neat cross field kick to spring another attack and when Dragons did win back possession they were met with tackle after tackle as Blues forced another penalty. Halfpenny this time stepped up from inside his own half but was short.
Dragons had a first shot at goal, after Halfpenny’s high up and under came back in the wind and Blues were caught offside. Tovey, though, saw his kick glance off the outside of the left post and away.
A penalty at the scrum against Blues, as it collapsed on impact, gave Tovey a chance to atone three minutes later, but he pushed his kick horribly wide right of the target.
Halfpenny rubbed salt in the wound as the very next attack saw Blues win a penalty at the breakdown and from the ten-metre line and wide left he confidently stroked his kick high and over.
Dan Evans broke tackles to attack from deep as Dragons looked to strike back and after stringing several phases together they went right and were turned over by the hard working Robin Copeland and Benoit Bourrust.
Slick hands through several men down the left saw Macauley Cook release Marc Breeze into space, but when the move broke down back came referee Leighton Hodges for a penalty at the ruck and Halfpenny did the rest for a 9-0 lead.
Dragons scored a try from nothing after Patchell kicked into space but saw the bounce evade Cuthbert and fall kindly for the visitors. They broke down the left and with the numerical advantage the ball was fed to Will Harries to score.
Gareth Davies replaced Rhys Patchell, who was injured in the last play, and Dragons again picked up the pace as they looked to build on the opening try of the game. And a penalty from Tovey on 33 minutes gave the visitors the lead.
A late counter attack in the first half saw Harry Robinson find space and when Gareth Davies arched his run he broke into space but failed to find any support on the wing as he threw the ball wide.
The second half started in torrential showers but it was the same story for Dragons as an early penalty was stroked over by Tovey for a 13-9 lead.
Blues looked to assert some pressure, as a hack ahead at the breakdown forced Tovey to dive into touch under pressure. But the hosts lost the lineout and with it vital momentum.
Phil Davies made a double change to try and spark his side into life, with Wales prop Gethin Jenkins making his return after injury in the autumn internationals.
Tovey hit a penalty low and right of the target as Blues escaped further punishment after another scrum penalty. Halfpenny was not as forgiving when Cook was taken out in the air on a lineout and made it a one-point game.
Blues produced their best period of the game as they went left and right with real endeavour and when Gavin Evans flicked out of a tackle the penalty was secured in front of the posts as Dragons failed to roll away from the tackle. Halfpenny put Blues back ahead with 16 minutes left.
A massive home scrum shunted Dragons off the ball as Copeland picked up and set off into tackles. And superb work at the breakdown by Navidi secured a penalty for holding on, but Halfpenny missed his long range kick left of the uprights.
Replacement Gareth Davies looked to relieve some of the building pressure as he slotted a neatly struck drop goal through the posts after Blues again looked to batter through the rock solid visiting defence.
The Blues scrum was becoming increasingly dominant to give the hosts a platform to build upon while Richie Rees was pinned offside to give Halfpenny a mammoth kick from deep inside his own half that had the distance but just went right.
A frantic final ten minutes saw Blues look to take control up front and as they drove around the field they secured a last minute penalty that Halfpenny eased over to ensure the Dragons left the capital empty-handed.
Timeline:
09m Patchell p 3-0
22m Halfpenny p 6-0
28m Halfpenny p 9-0
29m Harries t Tovey c 9-7
33m Tovey p 9-10
42m Tovey p 9-13
55m Halfpenny p 12-13
64m Halfpenny p 15-13
71m Davies dg 18-13
79m Halfpenny p 21-13
Cardiff Blues: 15 Leigh Halfpenny, 14 Alex Cuthbert, 13 Richard Smith, 12 Dafydd Hewitt, 11 Harry Robinson (Evans 40), 10 Rhys Patchell (Davies 30), 9 Lloyd Williams; 1 Sam Hobbs (Jenkins 47), 2 Marc Breeze, 3 Benoit Bourrust, 4 Macauley Cook, 5 Filo Paulo, 6 Rory Watts-Jones (Jenkins 47), 7 Josh Navidi, 8 Robin Copeland.
Replacements: 16 Rhys Williams, 17 Gethin Jenkins, 18 Scott Andrews, 19 Chris Dicomidis, 20 Ellis Jenkins, 21 Lewis Jones, 22 Gareth Davies, 23 Gavin Evans