Cardiff's Craig Conway and Don Cowie struck in extra time to kill off Huddersfield's Carling Cup hopes.
Gabor Gyepes and Jon Parkin headers put the hosts 2-0 up at the break.
But Jordan Rhodes slipped the ball under Tom Heaton after skipper Paul Quinn's mistake and Danny Ward equalised with a low shot.
Rhodes gave his side the lead, but Cowie levelled in added time before Conway and Cowie ensured a home win.
Conway was the provider as Gyepes rose to meet his cross and Parkin was on the end of a whipped-in free kick for the second.
But after the break Paul Quinn's mistake allowed Rhodes to score from close range.
The Cardiff goalkeeper was then beaten by Ward, whose effort travelled through a forest of legs into the net.
Rhodes struck after beating the offside trap to leave visiting fans believing their side were going to win.
But Cowie levelled two minutes into injury time.
The Bluebirds went back into the lead after Ward's run came to nothing and Whittingham sent Conway into free space with a long pass.
Conway's shot took a deflection to beat Ian Bennett and Cowie drilled home the Bluebirds' fifth goal to send League One Huddersfield away with nothing other than their pride intact following a gutsy performance.