Ricardo Vaz Te's late header put West Ham United into the Capital One Cup fourth round after Cardiff fought back from 2-0 down.
Ravel Morrison slid in Matthew Jarvis's cross after 60 seconds.
Jarvis added the second from Modibo Maiga's assist and Craig Noone hit back with a curling 20-yard shot.
Summer signing Peter Odemwingie opened his Cardiff account to level, but Vaz Te scored his second League Cup goal this season to settle the encounter.
Two days after losing to a late Tottenham winner in the Premier League, Bluebirds manager Malky Mackay made 11 changes.
And the Hammers took an early advantage. Cardiff kicked off but one minute later West Ham boss Sam Allardyce, in his 100th game in charge, was celebrating after Morrison beat Bluebirds captain Mark Hudson before lobbing the ball over goalkeeper Joe Lewis.
West Ham facts
Ricardo Vaz Te's winner was his 14th goal for West Ham and second in the League Cup this season.
He scored in the 2-1 win over Cheltenham in August, with Ravel Morrison scoring the winner that night.
The ex-Manchester United player followed his third goal in four starts by beginning the move that led to Jarvis's score.
Morrison found Maiga from the byeline and his pass gave Jarvis the chance to defy two defenders and see the ball squirm over the line.
Maiga, Vaz Te and James Collins squandered more home chances before Noone spectacularly made the most of Cardiff's first chance, curling in with his left foot.
That classy finish and a half-time dressing room meeting with boss Mackay prompted post-break urgency from the visitors.
Jordan Mutch's swerving shot that earned a corner off goalkeeper Adrian's save underlined Cardiff's threat.
And Mutch's run and cross gave Odemwingie the close-range chance to score for his new employers.
However, as extra time loomed Jack Collison's cross allowed Portuguese Vaz Te to head the winner.
Cardiff City manager Malky Mackay: "We had a mountain to climb with the way we started.
"I thought we were a shadow of ourselves in that first period but we scored a beautiful goal on the stroke of half-time to bring ourselves back into it.
"We had a conversation at half-time and certainly put West Ham on the back foot in the second half.
"To quieten the crowd to that extent at 2-2, I'm very proud of the players."
Live Text Commentary
Full Time The referee ends the match.90:00 +2:31
Shot by Peter Odemwingie went over the net.90:00 +1:21
James Collins manages to make a clearance.90:00 +1:17
Corner from the right by-line taken by Craig Noone.90:00 +0:31 Substitution
Substitution Nicky Maynard goes off and Rudy Gestede comes on.87:39
Assist by Jack Collison.87:39 Goal scored
Goal! - Ricardo Vaz Te - West Ham 3 - 2 Cardiff Ricardo Vaz Te grabs a goal with a headed effort. West Ham 3-2 Cardiff.85:00
Tommy Smith takes a shot.82:20
Craig Noone manages to make a clearance.82:12
Corner from the right by-line taken by Matthew Taylor.81:09 Substitution
Substitution Razvan Rat comes on in place of George McCartney.80:42
Corner from the right by-line taken by Matthew Taylor.80:33
Clearance made by Matthew Connolly.80:18
Corner taken by Matthew Taylor from the right by-line.79:49
Free kick taken by James Collins.79:39
Foul by Nicky Maynard on Jack Collison, free kick awarded.79:09
Corner taken by Craig Noone.78:47
Craig Noone takes the chance to get an effort at goal.75:21
Assist on the goal came from Jordon Mutch.75:21 Goal scored
Goal! - Peter Odemwingie - West Ham 2 - 2 Cardiff Peter Odemwingie scores a left footed goal. West Ham 2-2 Cardiff.
Matthew Taylor takes the free kick.71:34
Mladen Petric fouled by Matthew Connolly, the ref awards a free kick.71:22
Tommy Smith restarts play with the free kick.71:11
Jack Collison challenges Tommy Smith unfairly and gives away a free kick.69:35
Craig Noone takes a shot and missed to the right of the net.68:19
Shot by Nicky Maynard cleared the net.68:12
Craig Noone restarts play with the free kick.67:34
Matthew Taylor gives away a free kick for an unfair challenge on Declan John.65:29
James Collins restarts play with the free kick.65:12
Jordon Mutch is penalised for handball and concedes a free kick.64:56
Joe Lewis takes the free kick.64:41
Mladen Petric challenges Declan John unfairly and gives away a free kick.63:27
Header at goal by James Tomkins goes over the frame of the goal.63:18
Clearance made by Mark Hudson.63:13
Corner taken by Matthew Taylor from the right by-line.62:41
Jack Collison takes a shot. Joe Lewis parries the ball away.62:32
James Collins crosses the ball in from the free kick.62:19
Ricardo Vaz Te fouled by Craig Noone, the ref awards a free kick.60:51
Free kick taken by James Collins.60:32
Free kick awarded for a foul by Peter Odemwingie on James Tomkins.60:09
Header at goal by James Collins goes right of the post.59:55
Free kick taken by Matthew Taylor.59:45
Mohamed Diame fouled by Jordon Mutch, the ref awards a free kick.57:59 Substitution
Substitution Mohamed Diame is brought on as a substitute for Ravel Morrison.55:29
Free kick taken by Joe Lewis.55:08 Substitution
Substitution Tommy Smith joins the action as a substitute, replacing Joe Mason.54:45
The referee blows for offside.51:53
Matthew Taylor takes a shot and went wide of the right hand post.50:40
Corner taken by Jordon Mutch from the left by-line.49:11
James Collins takes the free kick.48:50
Unfair challenge on George McCartney by Peter Odemwingie results in a free kick.46:56
Nicky Maynard takes a shot. Adrian parries the ball away.46:42
Corner from the right by-line taken by Don Cowie.46:16
Jordon Mutch takes the chance to get an effort at goal. Adrian parries the ball away.45:01
The referee blows the whistle to start the second half.45:01 Substitution
Substitution Kevin McNaughton on for John Brayford.45:01 Substitution
Substitution Mladen Petric replaces Modibo Maiga.45:00 +2:15 Half time
Half Time It is the end of the first-half.45:00 +1:47
Joe Lewis takes the free kick.44:36 Goal scored
Goal! - Craig Noone - West Ham 2 - 1 Cardiff Craig Noone scores with their left foot. West Ham 2-1 Cardiff.44:22
Direct strike on goal from the free kick comes in from Don Cowie.43:36
Free kick awarded for an unfair challenge on Craig Noone by Ravel Morrison.42:18
Matthew Connolly manages to make a clearance.42:12
Free kick crossed by James Collins.41:50
Joe Mason concedes a free kick for a foul on George McCartney.41:14
Adrian Adrian restarts play with the free kick.41:07
Matthew Jarvis fouled by John Brayford, the ref awards a free kick.39:29
Ricardo Vaz Te takes a shot and cleared the net.39:04
Modibo Maiga makes a clearance.38:58
Corner from the left by-line taken by Don Cowie.37:04
Peter Odemwingie manages to make a clearance.36:56
Corner taken by Matthew Jarvis from the left by-line.33:49
Corner taken by Matthew Taylor.33:01
Free kick crossed by Matthew Taylor.32:17
Foul by Declan John on Ricardo Vaz Te, free kick awarded.29:51
Free kick taken by Joe Lewis.29:29
James Tomkins concedes a free kick for a foul on Matthew Connolly.29:20
Corner taken by Matthew Jarvis from the left by-line.24:20
Craig Noone takes a shot and missed to the left of the target.22:27
Ravel Morrison takes the chance to get an effort at goal. Joe Lewis safely holds on.21:50
Jordon Mutch restarts play with the free kick.21:43
Unfair challenge on Joe Mason by George McCartney results in a free kick.18:48
Shot by Modibo Maiga missed to the right of the target.16:56
Free kick taken by Adrian Adrian.16:48
Don Cowie is flagged offside by the assistant referee.16:31
Corner taken by Don Cowie.15:37
Joe Lewis takes the free kick.15:19
The official flags Jack Collison offside.15:04
Mark Hudson manages to make a clearance.14:57
Corner from the right by-line taken by Matthew Jarvis.14:31
Ricardo Vaz Te has an effort at goal.14:09
Clearance by Modibo Maiga.14:03
Corner from the right by-line taken by Jordon Mutch.13:05
Joe Lewis takes the free kick.12:45
Unfair challenge on Peter Odemwingie by Matthew Jarvis results in a free kick.11:46
Adrian Adrian restarts play with the free kick.11:44
Peter Odemwingie is caught offside.11:13
Nicky Maynard takes a shot.9:21
John Brayford restarts play with the free kick.9:00
Free kick awarded for a foul by Matthew Taylor on Joe Mason.7:17
Assist on the goal came from Modibo Maiga.7:17 Goal scored
Goal! - Matthew Jarvis - West Ham 2 - 0 Cardiff Matthew Jarvis slots the ball right footed into the goal. West Ham 2-0 Cardiff.6:22
Free kick crossed by James Collins.6:10
John Brayford gives away a free kick for an unfair challenge on Modibo Maiga.5:15
Free kick taken by Adrian Adrian.4:55
Ravel Morrison fouled by Joe Mason, the ref awards a free kick.4:25
Jordon Mutch takes the chance to get an effort at goal.2:43
James Tomkins restarts play with the free kick.2:31
Free kick awarded for an unfair challenge on Matthew Taylor by Jordon Mutch.1:00
Assist on the goal came from Matthew Jarvis.1:00 Goal scored
Goal! - Ravel Morrison - West Ham 1 - 0 Cardiff Ravel Morrison slots the ball right footed into the goal. West Ham 1-0 Cardiff.0:00
The referee gets the game started.
Live data and text provided by our data suppliers