The Hammers boss picked up a much-needed win but lost Guy Demel to a serious-looking injury and James Tomkins to a second yellow card even as Andy Carroll returned from injury
Allardyce has come under fire after the London club's run of seven Premier League games without a win and humiliating FA Cup and Capital One Cup thrashings at the hands of Nottingham Forest and Manchester City, respectively, in the previous week.
But Carlton Cole scored shortly before half-time at the Cardiff City Stadium before Mark Noble sealed the points in second-half stoppage time to ensure that Cardiff replace the Hamers men in the bottom three on goal difference.
West Ham had to dig deep for the victory as James Tomkins was sent off for a second bookable offence 18 minutes from time and they also lost Guy Demel to what appeared to be a serious injury in the first half.
|By Harry Sherlock
What a way for Sam Allardyce to prove his critics wrong. The West Ham boss got his tactics spot-on for this clash with Cardiff City and can leave Wales with his head held high, having masterminded a superb victory.
The Hammers looked hungrier than their fellow relegation-battlers and, even after Guy Demel's horrific injury and James Tomkins's silly sending-off, they remained calm and composed.
All that they need to do now is carry this form into their following match, against Newcastle, while Cardiff have to recover quickly if they are to climb out of the relegation mire.
Record signing Carroll was named in the West Ham squadfor the first time since his close-season switch from Liverpool, while Allardyce made five changes to the side who were hammered at City in midweek.
Cardiff centre-back Mark Hudson made his first Premier League start and new signing Magnus Wolff Eikrem was on the bench as Solskjaer also made five alterations to his starting line-up.
West Ham started brightly and the hosts breathed a sigh of relief when Stewart Downing's fourth-minute cross from the right evaded everyone and struck the far post before David Marshall denied Tomkins from the rebound.
Demel then became the visitors' latest injury victim when he was caught in the face by team-mate Roger Johnson's elbow after only seven minutes and was carried off wearing a neck brace following a lengthy stoppage.
Cardiff came tantalisingly close to opening the scoring after 31 minutes, when Kim Bo-Kyung's shot deflected over Adrian and struck the crossbar before bouncing down on the line, whereupon Frazier Campbell fouled the goalkeeper in his follow-up.
The visitors made the most of that fortune 11 minutes later, as Matt Jarvis picked out Cole with a precise ball across the face of the goal and the striker made no mistake from six yards out.
Cardiff were almost caught out again a minute later but Matt Taylor's right-footed effort whistled just past the far post.
The home side thought that they should have had a penalty during 10 minutes of added time when Craig Noone went down under a George McCartney challenge but referee Lee Mason waved play on.
Craig Bellamy made his return from injury when he replaced Peter Odemwingie at the break and the evergreen forward wasted no time in making an impact, swinging in a free kick that was headed over the bar by an unmarked Hudson.
Cardiff piled on the pressure and Adrian produced a fine reflex save to deny the lively Campbell 12 minutes into the second half after an inviting cutback from Bellamy.
Norway midfielder Eikrem came on to make his debut after 64 minutes and Bellamy curled a free kick just wide six minutes later as the hosts' frustration grew
Carroll replaced Cole a minute later to warm applause from the travelling fans but West Ham were reduced to 10 men when Tomkins was shown a second yellow card for a high challenge on Campbell in the 72nd minute.
However, the visitors stood firm and Noble sealed the points in stoppage time when he drilled the ball into the far corner after being played in by Carroll.