Aiden Flint's first goal of the season ensured Cardiff secured a 1-0 win over Swansea at the Liberty Stadium and a first victory in the South Wales derby since 2013.
Swansea headed into the game unbeaten in their previous four league games against Cardiff, but they fell behind inside eight minutes when Flint reacted quickest to Freddie Woodman's save from Marlon Pack's initial effort to head the ball into the roof of the net.
Steve Cooper's side dominated the second period, but came closest to levelling when Connor Roberts' corner was flicked onto the post by Andre Ayew.
But Cardiff held on to deny Swansea a league double over their rivals and with it move up to eighth in the Sky Bet Championship table, four points outside the plays. Swansea remain in third place, six adrift of Watford in second with a game in hand.
Resilient Cardiff boost play-off hopes
Swansea handed a first start to 20-year-old Morgan Whittaker in attack with Jamal Lowe - their two-goal hero in the reverse fixture - on the bench. Cardiff, meanwhile, were without in-form right-back Perry Ng.
Swansea's Conor Hourihane was fouled by Will Vaulks on the edge of the box early on. Hourihane stepped up and curled a free-kick towards goal which Dillon Phillips tipped wide for a corner. Cardiff responded by taking the lead from a trademark set-piece.
Vaulks launched in a long throw and it fell to Marlon Pack, whose poked effort on goal was brilliantly saved by Swansea goalkeeper Woodman but Flint reacted quickest to power home a header.
Swansea's eagerness to play out from the back was being tested by Cardiff's impressive pressing and Leandro Bacuna forced Woodman into action again from an away counter-attack.
Swansea's strife was not improved by them losing key man Hourihane, who had initially tried to run off a thigh muscle injury. Korey Smith was the man to come on. Cardiff captain Sean Morrison also headed a monster Vaulks free-kick wide, while Swansea's Jay Fulton and Matt Grimes put speculative efforts over the bar.
Just before the break, a Woodman error played in Cardiff striker Kieffer Moore, who ran in on goal but could not convert. Ryan Bennett got back to clear the danger.
The pace of Swansea's game improved at the start of the second period and Whittaker had a shot saved. Ayew was then fouled on the edge of the box by Vaulks to earn a home free-kick.
Ayew curled the resulting effort wide, with Phillips unbothered. Whittaker also blazed over when he should have at least hit the target, while at the other end Woodman denied Harry Wilson on another counter. Wilson had been quiet to that point.
Ayew came within inches of levelling the scores when his header from a Connor Roberts corner beat Phillips but not the post. Swansea introduced Lowe and Ryan Manning and switched to a back four in search of an equaliser, but although they dominated the ball, they could not break through.
What the managers said...
Swansea boss Steve Cooper: "We conceded a really soft goal from the throw-in, which we knew was coming. It was a cruel game really as we did everything but score. We were the superior team and created lots of chances, but we couldn't score and lost the game.
"That's the stat you don't want to be on the wrong end of. It's difficult to take, and the fashion of the loss as well. If you're going to lose a derby, you'd rather get well beaten maybe.
"For it to happen like it did is doubly difficult but we've got to stick together and be positive. We're still in a good league position."
Cardiff boss Mick McCarthy: "I'm delighted. I'm going to put a coat-hanger in my mouth upside down to keep the smile on my face all week! I'm absolutely thrilled for the lads as they've had to put a real shift in. It was a stoic performance.
"We knew they were going to play so we had to have a game plan. Pride and the bragging rights were at stake. Sean [Morrison] has been a fabulous defender for this team for years and for me he's been a real leader, driving people on.
"We've got a real weapon with the long throw and powerful players who can cause problems in the box. It's turned out to be the winner and it's important that goals come from everywhere. It was important not to be beaten going into two weeks off, so to go into the break with a win is better still to keep the momentum going. The fans will be delighted."
'Cardiff fans can't question attitude tonight'
Danny Gabbidon told Sky Sports:
"I thought Cardiff were poor in the second half and played most of the game in their own half - they couldn't string two passes together. Swansea were much better in the second half but Mick's side showed great determination and desire to defend their goal and to see the game out.
"They were dominated in all departments during the first game between these two sides at the Cardiff City Stadium, and fans questioned the hunger of some of the players. I don't think they can question the attitude of the players tonight. The desire was there to see and the captain Sean Morrison epitomised that."
Man of the match - Sean Morrison
Cardiff defender Sean Morrison told Sky Sports:
"We owed the fans this one. The last three derbies we've been way off it - we've lost two, drew one. We know how much this means for the fans, so this was for all those who couldn't be here today. It was a lot of pressure to carry. We spoke about it during the week and before the game [no side have done a league double in the derby], and we don't want to be on the wrong side of history.
"We weren't the best side with the ball, but we showed great fight, character and determination to come away with a 1-0 win. We're extremely happy."
Swansea travel to face Birmingham on Friday April 2 in the Sky Bet Championship at 8pm, live on Sky Sports Football. Cardiff City host Nottingham Forest on the same day at 3pm.