Bobby Zamora celebrated his home debut with the winner as West Ham stayed in
touch with the promotion pack.
The hosts dominated a lively encounter but were frustrated by fine saves by Cardiff goalkeeper Martyn Margetson and saw efforts rebound off the woodwork.
Zamora finally broke the deadlock after 73 minutes when he outstripped Danny Gabbidon for pace and coolly slotted the ball past Margetson.
Cardiff launched a late rally, but never looked like snatching a draw.
The visitors' had looked most dangerous on the break and Alan Lee, starting his first
game in three months, forced a smart early save from Stephen Bywater before Robert Earnshaw charged clear only to see his effort well saved.
Cardiff were soon dealt a blow when Rhys Weston hobbled off with an injury, but they were lucky not to go down to 10 men when centre back Gabbidon escaped with only a yellow card for bringing down Zamora.
Nigel Reo-Coker, one of six ineligible for the midweek FA Cup exit at the hands of Fulham, sent a fierce shot narrowly wide before Zamora and Christian Dailly both wasted excellent chances.
Zamora failed to connect properly to Jon Harley's left-wing cross before Dailly headed wide from Carrick's corner.
Matthew Etherington was then denied by a fine save from Margetson after a one-two with
Reo-Coker put the former Tottenham winger clean through.
Reo-Coker rattled the post with another long-range effort as the opening half
drew to a close.
The woodwork came to Cardiff's rescue again shortly after the restart when Zamora saw his left-foot shot bounce back off the crossbar.
Zamora continued to find space behind the Cardiff defence but another collective groan echoed around Upton Park as he sent a good chance wide.
The breakthrough finally came when Zamora ran on to Connolly's flick-on from the halfway line and finished coolly after bursting past Gabbidon.
West Ham: Bywater, Repka, Mullins, Dailly, Harley, Harewood,
Reo-Coker, Carrick, Etherington, Zamora, Connolly. Subs:
Srnicek, Nowland, Melville, McAnuff, Deane.
Cardiff: Margetson, Weston, Vidmar, Gabbidon, Barker, Boland,
Parry, Kavanagh, Langley, Earnshaw, Lee. Subs: Alexander,
Whalley, Prior, Robinson, Campbell.
Referee: G Cain (Merseyside).