Relief for Sam Allardyce and West Ham United, sackcloth and ashes for Ole Gunnar Solskjaer's Cardiff City. It is questionable whether the manager universally known as Big Sam could have survived another belittling defeat, but all that became academic when a performance that spoke volumes for the Hammers' team spirit ended a run of five losses in six games.

If the result was a timely fillip for Allardyce and his players, it was down to earth with a nasty bump for Solskjaer in his first home game in charge, after an encouraging FA Cup triumph at Newcastle a week earlier, and the next two league fixtures are against Manchester City and Manchester United, both away.

It was a bad day all round for Cardiff. Apart from losing at home to opponents previously regarded as the basket case of the Premier League, and dropping into the bottom three for the first time this season, supporters learned from newly published accounts that the club are now an eye-watering £118m in debt, having lost another £30m in their promotion season. The fact that £66m of this is owed to the owner, Vincent Tan, is unlikely to mollify the fans, among whom Tan is deeply unpopular after changing the Bluebirds' colours to red and sacking the local hero, Malky Mackay.

It was very much West Ham's day –at last. They took the lead just before half-time through Carlton Cole, then gutsily withstood Cardiff's second-half pressure, even after James Tomkins had been sent off for his second yellow card. By way of reward for their spirit the 10 men scored a second, through Mark Noble, in added time. Cole may have set up the win but the return of Andy Carroll as a second-half substitute was celebrated louder and longer by the East End legions.

Cardiff drop to 18th in the table after one win in their past 11 league matches.

Solskjaer had his new signing, Magnus Eikrem, on the bench until the 65th minute, when he replaced Gary Medel. Viewed as the replacement, sooner or later, for Peter Whittingham as playmaker and set-piece orchestrator, he made a decent start. Craig Bellamy, fit again after a two-month absence, went on for the second half as substitute for the ineffective Peter Odemwingie and galvanised a previously lethargic attack.

West Ham were immediately on the front foot, Adam Johnson striking Marshall's right-hand post with a cross-cum-shot from the right. Not long after that their injury jinx struck again, when Guy Demel was carried off and taken to hospital after a knock on the head sustained in an accidental collision with Roger Johnson.

Craig Noone, switching from right- to left-wing, made promising progress and delivered some penetrative crosses, but 31 desultory minutes had elapsed before Cardiff tested Adrián in the West Ham goal. Then Kim Bo-kyung accelerated through the middle before letting fly from 20 yards. The ball struck the crossbar and bounced down, over the line to the naked eye. Replays showed that the whole of the ball had not crossed the whitewash. One-nil, but only to goalline technology.

When Noone tried his luck from similar range, Adrián made a tumbling save.

Just as Cardiff seemed to be gaining the initiative, West Ham took the lead. Matt Taylor's ball over the top from the inside-right channel turned the defence and Matt Jarvis centred invitingly for Cole to sidefoot home from a central position, eight yards out.

Bellamy, introduced straight after half-time, might have set up the equaliser within two minutes with an inch-perfect free-kick that found Mark Hudson who, with a free header, was guilty of steering it well off target. Jarvis was similarly culpable but, after a run that bisected the centre-halves, the winger shot wastefully wide of David Marshall's right-hand upright.

With West Ham tiring after their midweek cup tie, Cardiff pressed forward in urgent pursuit of equality and they would have had it after 58 minutes but for a top notch save from Adrián, tipping over a shot from near the penalty spot with which Fraizer Campbell met Bellamy's centre from the right. Bellamy himself was desperately close with a 20-yard free-kick and then the pressure on the Hammers' defence increased when Tomkins received his second yellow card, for a foul on Campbell.

In extremis, Solskjaer switched to a back three, sending on Andreas Cornelius, the Danish international striker, in place of Hudson, but West Ham had the last word, Noble firing a second past Marshall in added time.

Allardyce declined to share his thoughts with the media after the game. Solskjaer said: "I was surprised we didn't have any energy or enthusiasm in the first half. But then Craig Bellamy came on and made a big difference. Our second half was outstanding, lacking only in goals. That's the way we want to play. We're in the bottom three but there's no panic. I never expected this job to be all singing and dancing."