Carlton Cole gave West Ham the lead in the first half before James Tomkins was sent off 18 minutes from time for a second bookable offence.
Cardiff piled the pressure on West Ham in the closing stages, but the visitors stood firm and made the game safe when Mark Noble scored a second goal deep into injury-time.
The win was the perfect response from West Ham after a difficult week as they spoiled Ole Gunnar Solskjaer’s first home game in charge of Cardiff.
West Ham made the brighter start of the two teams and almost hit the front after just four minutes when Stewart Downing’s cross from the left evaded everyone and bounced off the post. From the rebound the ball fell to Tomkins, but David Marshall was quickly off his line to block his effort
The visitors suffered a blow on ten minutes when Guy Demel appeared to be caught in the head by his own team-mate Roger Johnson with the full-back being forced off on a stretcher following ten minutes of treatment from the medical staff.
Demel was taken straight to hospital with a suspected broken elbow and facial injuries to add to Sam Allardyce’s injury woes.
Cardiff created their first opening of the game just past the half-hour mark when Craig Noone beat Demel’s replacement George McCartney down the left and he clipped over a cross which Fraizer Campbell headed over the top.
The home side thought they had taken the lead on 32 minutes when Kim Bo-kyung ran unchallenged to the edge of the box and saw his shot take a deflection off Johnson and loop over West Ham keeper Adrian and down off the underside of the crossbar onto the line. Campbell was then adjudged to have fouled Adrian as he bundled the keeper and the ball into the back of the net.
West Ham broke the deadlock on 42 minutes when Matt Taylor picked out Matt Jarvis inside the box and he crossed for Cole to slot home past Marshall from close range.
The visitors almost grabbed a second goal a minute later when the ball dropped to Taylor inside the box and he fizzed his right-footed shot just wide of the target with Marshall rooted to the spot.
Cardiff wasted a great chance to draw level early in the second half when Mark Hudson beat the West Ham offside trap to get on the end of substitute Craig Bellamy’s free-kick, but with his back to goal he could only head his effort over the top
The home side had strong claims for a penalty waved away on 59 minutes when McCartney appeared to haul down Campbell inside the box, but referee Lee Mason waved their appeals.
Adrian denied Cardiff the equaliser a minute later when he produced a superb reflex save to keep out Campbell’s powerful shot from ten yards out after Bellamy had picked out the striker inside the box.
West Ham introduced Andy Carroll for his first appearance of the season after a foot problem on 70 minutes, but two minutes later found themselves down to ten men when Tomkins was sent off for a second bookable offence after catching Campbell in the face with a high foot.
Cardiff threw everything at West Ham in the final 18 minutes, but could not find a way past Adrian or the visitors’ defence as they stood strong to repel their efforts.
West Ham made the game safe in the closing seconds when Carroll found Noble inside the box and the midfielder drilled his shot under Marshall to grab a goal his performance deserved to send the away fans into raptures.