Swansea City suffered a first defeat in five south Wales derbies as second-half strikes from Ollie Tanner and Aaron Ramsey proved the difference at Cardiff City Stadium.
Winger Tanner scored seconds after being introduced as a substitute to give the home side the lead on a sodden night.
And Ramsey added a second from the penalty spot after Tanner was adjudged to have been brought down in the area with five minutes remaining.
Head coach Michael Duff had named a side showing five changes from the defeat to Bristol City as Josh Tymon and Kristian Pedersen made their debuts, with Jamal Lowe, Joe Allen and Harry Darling all coming into the side.
However, the Swans were forced into a late change as Allen suffered an injury in the warm-up, with Jay Fulton coming into the starting XI and Mykola Kuharevich coming onto the bench.
Amidst a raucous atmosphere, it was little surprise to see a fast and frenetic start with neither side able to settle or find any real pattern in the hustle and bustle.
It took 10 minutes for either side to fashion anything that could be classed as an opportunity, with Cardiff keeper Jak Alnwick punching away a Charlie Patino cross as Darling closed in at the far post.
Karlan Grant fired straight at Carl Rushworth at the other end, but the offside was quickly and correctly raised.
When opportunities did present themselves the final ball was lacking, Rushworth tipping away a Jamilu Collins cross, while Josh Key saw his attempted centre deflected into Alnwick’s arms.
Swansea had a decent spell of pressure after the 20-minute mark, Tymon whipping in two deliveries that Cardiff scrambled clear, before skipper Matt Grimes volleyed wide from distance.
At the other end Nathan Wood made a terrific covering tackle as Grant looked to get in down the Swansea right.
Tymon was enjoying a lively debut, bringing plenty of energy down the Swansea left flank, but he and his teammates were able to return to the dressing room with the game goalless after Rushworth made a tremendous low save to deny Yakou Meite’s effort on the turn in the final seconds of the half.
The second half started as the first had ended, Rushworth making an instinctive save from Meite after the Cardiff forward had taken aim from distance.
A lovely gliding run out of midfield from Patino got the Swans on the front foot but the move ran out of impetus and Cardiff were able to clear.
Rushworth denied Meite again before Patino was unable to pick out a surging run from Tymon as the hour mark arrived with the contest still goalless.
Duff sent on Jamie Paterson and Josh Ginnelly for Lowe and Jerry Yates while the Swans then had to survive a period with 10 men as Patino required treatment on a cut to his head.
Ginnelly and Paterson quickly combined to create a half-chance, with the former seeing his shot blocked after getting the ball back from his fellow sub.
Fulton then made a goal-line clearance to keep out Grant’s effort back across goal, seconds later Tanner emerged from the bench and made an immediate impact as he opened the scoring.
The winger brought in a crossfield pass, and cut inside to arrow a strike into the far corner of the net.
Tanner was involved again a few minutes later, getting into space before delivering a cross that Grant headed over when unmarked.
Liam Cullen was introduced for the Swans and his run helped the visitors have an extended spell in the Cardiff half as they sought a leveller in the final moments.
But any hopes of a leveller were ended when Tanner surged forward again and was adjudged to have been fouled inside the box.
Ramsey stepped up to take the spot-kick and steered the ball into the corner of the net.
Fulton had a firm volley saved by Alnwick in stoppage time, while Ginnelly could not connect with Grimes' pass a few moments later.
Swansea City: Carl Rushworth; Harry Darling, Nathan Wood, Kristian Pedersen (Mykola Kuharevich 90); Josh Key, Jay Fulton (Ollie Cooper 90), Matt Grimes (captain), Charlie Patino (Liam Cullen 82), Josh Tymon; Jerry Yates (Josh Ginnelly 63), Jamal Lowe (Jamie Paterson 63).
Unused Substitutes: Andy Fisher, Ben Cabango, Harrison Ashby, Bashir Humphreys.
Cardiff City: Jak Alnwick, Dimitrios Goutas, Mark McGuinness, Ryan Wintle, Aaron Ramsey (captain) (Callum Robinson 90), Ike Ugbo (Ollie Tanner 70), Karlan Grant, Jamilu Collins, Yakou Meite (Kion Etete 81), Manolis Siopsis, Perry Ng.
Unused Substitutes: Alex Runarsson, Joe Ralls, Ebou Adams, Jonathan Panzo, Rubin Colwill, Andy Rinomhota.
Referee: Samuel Barrott