New Zealanders Ben Blair and Paul Tito did the scoring for Dai Young's men, with Blair converting Tito's 33rd-minute try and succeeding with four penalty attempts.
That helped Cardiff establish a 19-3 lead but the Scarlets, beaten by Glasgow and Munster in recent weeks, hit back with tries from David Lyons and Jonathan Davies in the closing quarter.
Those scores made a real game of it and stout defence was needed on Cardiff's behalf as they determinedly hung on to their four-point lead throughout a lengthy spell of injury-time.
A relieved Young said afterwards: "We certainly don't make things easy for ourselves. I thought for 65 minutes we played some good stuff and we always threatened to cut loose.
"But you've got to give the Scarlets credit. Once they sniffed a little bit of blood, they came for the jugular and we were lucky to get away with it in the end.
"I'm just pleased to get the win."
For the Scarlets' first visit the Cardiff City Stadium, coach Nigel Davies made one change to the side beaten at home by Munster last weekend - Richie Pugh coming in for the injured Dafydd Jones (knee) at openside flanker.
2009 Lion Matthew Rees and young half-backs Tavis Knoyle and Dan Newtown also made the visitors' bench, while Stephen Jones was rested due to a minor ankle injury.
Cardiff welcomed back fit-again centre Tom Shanklin for the first appearance since dislocating a shoulder against the Dragons last May.
The home side, losers in four of their last five meetings with the Scarlets, got on top early on, ploughing forward with attack after attack but Blair hit a post with his first penalty attempt.
Australian Sam Norton-Knight, brought back in at fly-half after a difficult opening few games, also missed the target with a drop goal shot.
Norton-Knight ran the Blues back-line well, linking with Shanklin and Jamie Roberts before his half break almost led to a try for Blair in the left corner. Xavier Rush also had a hand in the move.
It was left to Scarlets full-back Daniel Evans to open the scoring with an eighth minute penalty, which Blair cancelled out three minutes later.
Number 8 Rush was involved again as Cardiff broke through for the game's opening try, seven minutes before the interval.
After a barnstorming run up the touchline from Richard Mustoe, the Blues showed great hands to spread the ball wide again and Rush flipped a pass back inside for his fellow Kiwi Tito to touch down.
Blair fired over the conversion and added a superb penalty from distance. 13-3 ahead at half-time, the Blues did suffer a setback before Blair's penalty when Roberts went off injured after colliding with powerful Scarlets winger Sean Lamont.
Lamont had beaten Shanklin on the outside earlier in the half as the visitors pressed for a try but the attack petered out with Mustoe covering well.
Evans missed the first penalty of the second half, from far out, before Blair boosted the Blues with his fourth successful kick of the night.
With Andy Powell adding his bulk to proceedings, Cardiff were forced errors from the Scarlets - Taufa'ao Filise charging down a clearance kick and Gareth Thomas winning turnover possession courtesy of a muscular tackle on Mark Jones.
In a free-flowing encounter, Cardiff managed to add to their lead when Norton-Knight won a penalty which Blair sent through the uprights.
Rallying well, the Scarlets came out fighting for the final 20 minutes and Cardiff needed a big hit by Shanklin on Gareth Maule to keep their try-line intact.
On as a replacement, Lions hooker Rees went close to dotting down for Davies' charges. Yet, from the resulting scrum, five metres from the whitewash, number 8 David Lyons used his power to barge past Norton-Knight and over for a morale-boosting try.
Evans converted and the Scarlets closed the gap to just four points when they spun the ball wide, Rhys Priestland finding a hole and laying off for centre Davies to gallop over from 40 yards out for a fine try. Evans failed with his conversion attempt.
The tension increased for Blues fans when the men in red kicked a close-in penalty to touch. They won the lineout within sight of the home line and battered away, inching ever close to the posts.
However, the Cardiff forwards, minus hand injury victim Rush, defiantly stood up and were counted as they defended for their lives, keeping their Welsh rivals at bay and sending the vast majority of the 12,1918 attendance home happy.
|Cardiff Blues Score Card|
|Scarlets Score Card|