Joe Ralls' hat-trick saw him take his season's tally to five goals

Joe Ralls' hat-trick helped Cardiff City to victory over Birmingham City in a contest that ended with both sides reduced to 10 men.

Cardiff's Danny Ward was sent off in the 52nd minute when the score was 2-1, while Harlee Dean was red carded for Blues in stoppage time.

Kristian Pedersen put Birmingham ahead, but a contentious Ralls penalty and Curtis Nelson's goal turned the game on its head before Ralls' curler gave the Bluebirds a cushion.

Ivan Sunjic's goal set up a Grandstand finish but a second Ralls spot-kick in injury time sealed victory.

Cardiff remain 14th in the Championship, one point and two places below Birmingham.

Heading into this contest no side had scored fewer goals on the road in the Championship than Birmingham City and a lack of cutting edge could not have been more apparent in the first quarter of the match when they were utterly dominant as Cardiff's Swansea hangover was abundantly clear.

The visitors registered nine shots on goal before the Bluebirds' contentious penalty and will wonder how they were not able to carve out a lead greater than 1-0. Such was their dominance that Bluebirds fans started chanting "sort it out" towards boss Neil Warnock midway through the first half.

Blues started on the front foot and kept coming at Cardiff, with the impressive Dan Crowley the orchestrator.

They led after three minutes through a simple goal, with Pedersen poking home after Neil Etheridge saved Lukas Jutkiewicz's header from a Fran Villalba free-kick, but was only able to parry it into the path of Kerim Mrabti.

Kristian Pedersen's early goal for Birmingham was his third of the season

The goal sparked the visitors and Jude Bellingham should have done better from a fine cross than blazing over the bar from close range.

Crowley then hit the inside of the post with Etheridge beaten, with the home goalkeeper lucky not to concede an own goal as the ball struck his back and bounced to safety.

However, Etheridge atoned with a splendid save to tip over Jutkiewicz's powerful near-post shot as Birmingham failed to extend their lead.

Cardiff had not created an effort before Danny Ward turned a Nathaniel Mendez-Laing cross just wide on 26 minutes, but they levelled soon after thanks to the first of two penalties.

Referee Andrew Madley pointed instantly to the spot when Dean was adjudged to have pulled the shirt of Aden Flint, but the Birmingham players were extremely unhappy with the decision and the infringement was tough to spot.

Danny Ward was one of two players red carded

The goal inspired Cardiff and they led when Nelson bundled home at the second attempt from close range after Lee Camp could only block Flint's towering header.

The visitors were rocked and Camp had to tip over Junior Hoilett's powerful effort to prevent them falling further behind, while Nelson saw a goal ruled out just after the break after Flint was penalised for his own shirt tug.

However, Ward's reckless lunge on Mrabti saw the momentum swing away from the hosts with 38 minutes left to play, with Birmingham looking to find parity.

But a sucker-punch on the counter-attack ended their resilience, with Mendez-Laing's powerful run culminating in a pass to Ralls, who curled home exquisitely.

The goal deflated Birmingham, who have now failed to win on their last seven trips to the Welsh capital, but they did manage a consolation goal when Sunjic lashed home from 20 yards.

However, their momentum was squandered when Dean was sent off for leading with an elbow in a challenge on Ralls and Cardiff made the points safe when Ralls slotted home a second penalty after Marc Roberts fouled sub Omar Bogle.

What they said

Cardiff City manager Neil Warnock told BBC Sport Wales:

"The lads were really nervous to start with, I am tremendously proud of the character they showed, they knew how bad they were at Swansea. The only way to get the fans back in favour was to show how much it means to us and we did that, I am so proud of them all.

"I was chanting with the fans 'Warnock sort it out' I was thinking, 'come on, get a grip' so I am pleased I managed to sort it out as we have a great group of fans and you couldn't blame them for being upset last week.

"When we play well there are not many better teams than us in the division… so the season starts now really.

"It is one of the best wins since I have been at the club, under the circumstances. You could see how nervous the players were… We had to put a performance on for the fans and we did. They stayed and saluted us even though they must have been wet through."

Birmingham City's caretaker head coach Pep Clotet said:

"It was a game with a little bit of everything, a lot of emotions and intensity.

"For us, we feel that we leave Cardiff without receiving what we deserved.

"Cardiff had all the luck when it comes to transforming those chances and we didn't. We knew it was a very difficult game for us… but the players played the way we want to play.

"In total we had 25 shots on goal and still only managed to score two goals. It is a platform for us, but we need to learn to put a game to bed as soon as we can. All the opportunities Cardiff had in the game they took. But the first half is how we all want to see Birmingham City play.

"I will watch the Harlee Dean red card again, but we will consider an appeal."