A double blast from Junior Stanislas and a third from Zavon Hines finally shot down Millwall 3-1 on an explosive East End night of shame at Upton Park.
But West Ham needed extra-time to earn their place in the third round of the Carling Cup after a 25th minute strike from Neil Harris took Millwall to within just four minutes of slaying their Premier League hosts.
Unbeaten in their first five games of the season, Kenny Jackett's in-form side had made four switches as Alan Dunne, Scott Barron, Chris Hackett and Harris replaced Jason Price, Tony Craig, George Friend and Adam Bolder following Friday night's goalless draw at Southend United that had left the Lions sitting in eighth place in League One.
With a police helicopter encircling a tense Upton Park, the tensions on the streets of east London soon percolated down on to the pitch where Andy Frampton and Danny Gabbidon quickly collected the first pair of seven yellow cards for forceful fouls on Carlton Cole and Hackett.
As the tackles flew in, goal chances were few and far between in those frenetic opening exchanges, but on 25 minutes Harris drew first blood for Millwall.
Barron's long throw into the penalty area eventually landed at the feet of the lethal striker and he expertly prodded the ball beyond Robert Green from eight yards.
And with the vociferous band of 1,500 south Londoners still celebrating that Harris strike, only the bravery of the Hammers keeper prevented the visitors from doubling their shock lead when he courageously dived into the studs of the overlapping Dunne.
Hines replaced Josh Payne for the restart in a bid to give West Ham the zip and zest that had been so lacking in that opening period and, on 48 minutes, Jack Collison - bravely playing despite the death of his father in a tragic motorcycle crash on the way to Sunday's game - curled a delightful 18-yarder on to David Forde's right-hand upright.
Shortly afterwards, Cole out-muscled Barron before blasting high and wide, before Gianfranco Zola also introduced forward Frank Nouble at the expense of Radoslav Kovac.
With 20 minutes remaining, West Ham finally forced their first corner of a frustrating evening but James Tomkins headed high over and then Stanislas steered his volley off target too.
Frampton almost put the tie out of the Hammers' reach with a thumping 18-yard volley that Green punched away and that proved the turning point, for with just four minutes remaining, Stanislas popped up the far post to force Julien Faubert's deep cross home and spark an unsightly pitch invasion plus extra-time.
On 97 minutes, the sliding Frampton then handled Hines' low cross into the area and Stanislas coolly sent the consequent spot-kick to Forde's right to detonate more unwelcome encroachments onto the pitch that will undoubtedly lead to an FA inquiry.
With an ugly tie now turned well and truly on its head, Hines then burst past a trio of leggy Lions' defenders and blasted a 10-yarder beyond the helplessly exposed Millwall keeper to finally book West Ham's place in the third round.