Wales fly-half Jarrod Evans kicked a late penalty to help Cardiff Blues complete a hat-trick of victories over Scarlets this season.
Evans orchestrated the win with a 14-point haul, with Cory Hill, Hallam Amos and Josh Turnbull also claiming tries.
Scarlets had battled back from 26-9 down with two tries from replacement scrum-half Dan Blacker and a score from Angus O'Brien.
A charged-down Leigh Halfpenny conversion attempt proved crucial.
Cardiff had completed a Pro14 league double over Scarlets before this narrow success in the new Rainbow Cup competition.
Scarlets completed a turbulent week following the departure of head coach Glenn Delaney, announcing his exit less than an hour after the 22-6 win over Ospreys last Saturday.
Dwayne Peel will take charge next season as head coach after Delaney was initially meant to be moving up to a director of rugby role.
Dai Flanagan has been given the interim head coach job until the end of the season and made five changes in his first selection, with centre Ioan Nicholas returning for the first time since October 2019.
British and Irish Lions 2021 duo Gareth Davies and Ken Owens were named as replacements, but Davies was a late withdrawal through illness with Blacker coming in.
Lion-in-waiting Josh Adams was named on the Cardiff Blues wing as Dai Young welcomed back Wales Six Nations trio Tomos Williams, Jarrod Evans and Willis Halaholo.
Halfpenny opened the scoring with a penalty before Cardiff Blues fly-half Evans burrowed over for a converted try.
Evans' excellent range of passing and the creativity of centres Ben Thomas and Halaholo were in evidence and almost helped lead to a Turnbull try, but the Cardiff captain was denied by a last-gasp Tom Rogers tackle.
The visitors' dominance was again repelled by a steal from Scarlets flanker Jac Morgan, before the inevitable second try followed as Hill sliced through the home defence.
Halfpenny reduced the deficit with his second penalty before Cardiff Blues full-back Amos glided over for a impressive individual effort. Halfpenny's third successful kick at least trimmed the hosts' deficit to 10 points at half-time.
Cardiff Blues maintained their attacking intent and Turnbull barged his way over for the bonus point fourth try, before Adams was handed a rest.
Scarlets retaliated with a Blacker try after a strong surge from Johnny McNicholl with Halfpenny's conversion charged down by Jason Harries, with those two missed points eventually proving vital to the result.
Blacker popped up again for his second try after a Rogers burst, with the score standing following an unsuccessful captain's challenge from Turnbull.
Jarrod Evans burst through Scarlets defence but chose not to pass and the home side cleared their lines to set up the foundation for the third try for O'Brien after he latched onto a clever grubber-kick from Dan Jones.
O'Brien converted to give Scarlets the lead with five minutes remaining, before Evans restored Cardiff Blues' advantage and ultimately clinched the victory.
Scarlets skipper Owens tried to lodge his own captain's challenge before Evans' kick, claiming an opposing player had come in from the side.
Without reviewing the incident, Irish referee Sean Gallagher ruled that was not a case of foul play and not leading to a try, so there could be no challenge.
That caused confusion with suggestions you can challenge anything in the last five minutes of a game. Evans ignored the uncertainty and proved the match-winner.
Scarlets interim head coach Dai Flanagan: "The week has been great and I have been supported by the players.
"You could see the effort put in at the end of the game and they want to fight for things. It was just disappointing we left ourselves so much to do.
"We were fortunate to still be in the game at half-time and that's where we need to find the answer, because we can't be relying on coming back all the time.
"Dane Blacker has been outstanding and is a pleasure to coach. He works hard and is tough and I am chuffed how he went today."
Cardiff Blues director of rugby Dai Young: "There were a couple of pleasing things but the most pleasing thing was to come down here and get a victory.
"It's a tough place to come and win. The last five minutes in the last two games have been nip and tuck and we found a way to win today.
"We ran the clock down and I think in the early part of the season we'd have lost those games. If you look at the Connacht and Munster games, the last five or six minutes we let those games get away from us.
"It's nice to think we have learnt from our defeats."
Scarlets: Leigh Halfpenny; Tom Rogers, Jonathan Davies, Ioan Nicholas, Johnny McNicholl; Angus O'Brien, Kieran Hardy; Rob Evans, Ryan Elias (capt), Alex Jeffries, Josh Helps, Lewis Rawlins, Aaron Shingler, Jac Morgan, Ed Kennedy.
Replacements: Ken Owens, Steff Thomas, Javan Sebastian, Morgan Jones, Iestyn Rees, Dane Blacker, Dan Jones, Joe Roberts.
Cardiff Blues: Hallam Amos; Jason Harries, Willis Halaholo, Ben Thomas, Josh Adams; Jarrod Evans, Tomos Williams; Rhys Carré, Kristian Dacey, Dillon Lewis, Seb Davies, Cory Hill, Josh Turnbull (capt), Olly Robinson, James Ratti.
Replacements: Liam Belcher, Corey Domachowski, Keiron Assiratti, Rory Thornton, Gwilym Bradley, Lloyd Williams, Dan Fish, Harri Millard.
Referee: Sean Gallagher (IRFU).
Assistant Referees: Gwyn Morris, Elgan Williams (both WRU).
TMO: Wayne Davies (SRU).