The hosts thrived on the charged atmosphere, starting energetically and registering the game’s first shot with Joe Ralls’ volley wide.
Derby soon settled, however, and kept the ball for long periods with their five-man midfield stifling Russell Slade’s side.
For all their possession, the visitors failed to trouble Cardiff’s defence, and it was one of the Bluebirds’ back four who gave them the lead.
Peter Whittingham’s outswinging corner floated temptingly towards the back post, where centre-back Ecuele Manga timed his jump perfectly and headed the ball powerfully into the top corner.
Having failed to muster a shot on target in a blunt first-half display, Derby managed one four minutes into the second half with Martin’s equaliser.
After the striker’s initial shot was blocked, the ball ballooned into the air and Martin seized on the rebound before Cardiff keeper David Marshall to head in from close range.
The home side could have reclaimed the lead within seconds, but Craig Noone’s shot was well saved by Scott Carson.
Scott Malone was the next to test Carson with a neat half-volley as Cardiff upped the ante before eventually scoring their second goal.
Whittingham was the creator again, his corner nodded down by Sean Morrison into the path of O’Keefe, who scrambled the ball in from close range for a winning goal met with rapturous celebrations in the stands.
Cardiff manager Russell Slade:
“It was a very professional performance. There weren’t many chances but we made enough use of the ball to create enough chances to win.
“What pleased me most was that when Derby got themselves back into the game early in the second half, there was a great response from us and we got the all-important second goal.
“We’ve got a mountain-load of character and we showed that in front of a big crowd to win a big game.
“However the challenge remains to get into the top six. Despite winning, we are still a couple of points adrift and we are running out of games.”
Derby head coach Darren Wassall:
“We’re very disappointed, particularly on the back of such a good result against Nottingham Forest two weeks ago.
“It’s unacceptable to concede two goals from set-pieces. Our defending at home has been good but on the road it just hasn’t happened for us.
“The lads are hugely disappointed because there was very little in a game of few chances. But that just makes conceding two goals from corners all the more disappointing.
“We came out of the blocks quickly for the second half and Chris (Martin) was brave with the header for the goal and we all thought we would kick on from there.”