Cole opened the scoring with an acrobatic header
A cruel own goal by Sunderland keeper Craig Gordon helped West Ham to a fortuitous victory at Upton Park.
The Hammers went ahead on nine minutes as Carlton Cole twisted to head George McCartney's cross into the top corner.
Kenwyne Jones was a constant threat as Sunderland fought back and he levelled after the break with a firm header.
But substitute Nolberto Solano's shot hit a post and went in off Gordon's boot, and Craig Bellamy made sure with an injury-time third on the break.
One of the best chances of the match came in the first minute, Jones finding space inside the six-yard box but heading Ross Wallace's corner over the bar.
McCartney, facing his former club, was the architect of the first goal, chesting down a Hayden Mullins crossfield pass and sending in a teasing cross from the left flank.
Cole had plenty to do, as the ball was behind him and angling away from goal, but he turned his body superbly to head into the top corner.
Hammers keeper Robert Green needed to be alert to turn round a speculative 20-yard left-footed strike from Jones.
Sunderland had their fair share of possession but it was profligacy from West Ham that led to their next chance, Mark Noble gifting the ball to Liam Miller, who shot straight at Green when well place on the edge of the area.
Roy Keane made a double change at half-time and his team had much the better of the play for the majority of the second period.
Jones got a deserved equaliser with a superb leap and a firm header into the bottom corner and his aerial threat was soon evident again as he flicked on Gordon's punt downfield.
Grant Leadbitter collected the ball in his stride and ghosted through the defence before unleashing a drive that thudded against the inside of the post, Green at full stretch getting an all-important touch on the stinging left-foot shot.
Jones even proved effective in defence when he managed to prevent Cole getting maximum power with his shot on the turn and Gordon gathered.
Sunderland continued to cause problems from set pieces and Dickson Etuhu went close with a header that Noble cleared on the line.
With West Ham failing to cope with the crosses, Jones drifted clear again but his header flashed past the post.
But it was a substitution from Alan Curbishley that led to the winning goal, in the most unfortunate of circumstances for Sunderland.
Solano replaced Noble and clinically pounced on a loose ball inside the area.
As Gordon lay on the turf having seen the former Newcastle midfielder's cool effort come back off the woodwork, the ball connected with his outstretched right foot and rolled agonisingly into the net.
Understandably the goal knocked the stuffing out of Sunderland and as they pressed in the dying moments, Luis Boa Morte broke down the left and crossed for Bellamy to flick home at the near post and give the scoreline an unfair reflection.
West Ham boss Alan Curbishley:
"We were fortunate but another time we might have the lion's share and come away with nothing.
"I was expecting more in the second half but we were stunned by their goal and Sunderland grew in stature.
"They came onto us and we did look dangerous on the break."
Sunderland manager Roy Keane:
"Annoyed would be an understatement.
"You make your own luck and we've got to stop giving away bad goals.
"I made a mistake with the three in midfield but changed it and we got the goal back. I always thought the next goal was going to win it."
West Ham: Green, Neill, Gabbidon, Upson, McCartney, Bowyer, Noble (Solano 73), Mullins, Etherington (Boa Morte 74), Cole (Ferdinand 84), Bellamy. Subs Not Used: Wright, Camara.
Booked: Cole, Bellamy, Bowyer.
Goals: Cole 9, Gordon 78 og, Bellamy 90.
Sunderland: Gordon, Halford, Nosworthy, Higginbotham, Collins (Harte 80), O'Donovan (Chopra 46), Leadbitter, Miller, Etuhu, Wallace (Stokes 46), Jones. Subs Not Used: Ward, Connolly.
Booked: Leadbitter, Halford.
Goal: Jones 52.
Ref: Chris Foy (Merseyside).