Dimitrios Goutas and Karlan Grant both scored their first goals for Cardiff as the Bluebirds made it back-to-back wins in the Championship for the first time this season.
Their 3-2 home win over Coventry pushed them into the top half of the table and saw the Sky Blues drop to 15th. Kion Etete polished things off for the home side with a goal with his first touch in the 84th minute.
Matt Godden scored twice for the visitors, levelling the scores in the first half and then heading home his second in the 95th minute.
Cardiff boss Erol Bulut opted to rest Wales skipper Aaron Ramsey after his two games for club and country last week but rewarded Ollie Tanner for scoring his first goal for the club in the 2-0 win over Swansea by giving him his first start at home in the Championship.
- Championship fixtures | table | highlights
- Stream the Championship and more with NOW
- Get Sky Sports | Download the Sky Sports App
It had taken Tanner a mere 40 seconds to score with his first touch after coming on at the weekend and he was the first into the thick of the action for the Bluebirds playing in a wide right position as he tested the Coventry defence.
He flashed a header past the post in the fifth minute and then saw Greek defender Goutas follow in his footsteps three minutes later by scoring his first goal for the club as he powered home a free header from a Joe Ralls corner.
The home side were good value for their lead and almost got a second in the 33rd minute when a Ryan Wintle cross from the right edge of the box was turned inches wide by Ike Ugbo from the middle of the six-yard box.
Coventry arrived in the Welsh capital sitting two places above their hosts but on the same number of points. Having absorbed most of the pressure in the opening half-hour, they hit back in the 33rd minute from a corner.
Jak Alnwick punched the ball away from his goal, but only as far as the edge of the D. Milan van Ewijk immediately stroked a pass to his left to skipper Liam Kelly, whose first-time touch into the area found Godden to turn on the edge of the six-yard box and bag the equaliser.
It was his fifth goal in eight games to underline just why the Sky Blues were so keen to get him to sign a new contract last month.
All of a sudden there was a real spring in the step of the visitors and when Tatsuhiro Sakamoto was introduced eight minutes into the second half they got even livelier.
Cardiff, though, regained the lead just after the hour mark after they swept the play upfield and Ralls carried across field to give Tanner and Wintle the chance to combine on the right. It was Wintle’s measured cross that enabled West Brom loanee Grant to stoop low and head home from eight yards.
Alnwick had to be at his best in the home goal to stop Kasey Palmer from levelling in the 71st minute when he shot from 10 yards out.
Etete fired across goal to hit the left corner to make it a two-goal lead and though Godden scored his second of the night in the fifth of the 10 added minutes it was too little, too late.