Roger Johnson scored his seventh goal of the season
Gary Johnson was sent from the dug-out as Bristol City's Championship title hopes were controversially dented by a Peter Whittingham-inspired Cardiff.
Roger Johnson's first-half header broke the deadlock from Whittingham's left-wing free-kick before Dele Adebola headed a leveller in the 73rd minute.
Bristol City's Steve Brooker then had a goal ruled out but a minute later, the hosts won it from the penalty spot.
Whittingham needed two attempts to score after Stephen McPhail was fouled.
Cardiff City boss Dave Jones: "It certainly was a full-blooded, ding-dong derby match.
"We had a couple of situations where we out-numbered them and we didn't take advantage. Then we lost our shape trying to get a second goal and we let them back into the game.
"Brooker's effort, though, was off-side but our fight showed that our semi-final against Barnsley at Wembley is the furthest thing from our mind.
"My players know that no-one is guaranteed a place in that game unless their performances are of a consistently high standard."
Bristol City boss Gary Johnson:
"I was sent off for trying to get the ball back into play. The fourth official was holding on to the ball too long and all I did was try to grab it off him.
"It was a difficult afternoon all-round for us - because one minute we thought we had won it and then a few minutes later we conceded a penalty and went behind.
"We have to get over it. There are six games left for us to obtain the points we need for promotion."
Bookmark with:
What are these?