Darren Bent scored the winner in the 69th after Dimitar Berbatov cancelled out Steven Naismith's opener.
Cardiff had staged a fightback after trailing 2-0 to West Ham before going out of the competition.
The hosts' lead, secured by Ravel Morrison and Matthew Jarvis, was wiped out by Craig Noone and Peter Odemwingie, but the London club recovered with Ricardo Vaz Te netting the winner.