Penalties were needed in the third-round replay at the Boleyn Ground following a dramatic 2-2 draw after extra time.
Enner Valencia gave the Hammers the lead early in the second-half and things got worse for the visitors when Aiden McGeady was sent off for two bookable offences.
Roberto Martinez threw on Kevin Mirallas and he was the difference, firing a magical free-kick past Adrian with just eight minutes remaining to send the game into extra time.
Romelu Lukaku gave his side first blood after the restart, firing home Mirallas’ cross, but Martinez’s side could not hold on for a famous victory.
Allardyce brought on Carlton Cole as his side went in search of an equaliser and the move worked as the substitute stabbed home James Tomkins’ knock down with his first touch to take the game to penalties.
And Adrian was the hero for the home side, saving Steven Naismith’s spot kick before scoring the winning penalty himself after Joel Robles missed for Everton.
West Ham‘s reward after a pulsating 120 minutes of football is a trip to Ashton Gate to face in-form League One side Bristol City.
Both managers were true to their word in selecting strong sides with Allardyce re-calling Matt Jarvis and Alex Song to the side that drew with Swansea, while Martinez stuck with the same team that held champions Manchester City on Saturday.
But part of Everton’s problems this season have been individual errors and despite their bright opening 10 minutes they could have been behind after John Stones was caught in possession by Valencia, but the forward’s shot was well saved by Joel.
The rebound fell into the path of Andy Carroll but the striker’s header crashed against the post, however it would not have counted with the England striker judged to be in an offside position.
Everton were now starting to dominate proceedings and looked the more likely to open the scoring as McGeady saw his shot blocked, but Allardyce’s men remained a threat on the counter-attack through Valencia and Stewart Downing.
Just after the half hour mark, the Ecuador international released Downing down the right, whose cross picked out the late arriving Song, but his shot hit Valencia when it looked to be heading into the back of the net.
The second half started in much the same vein as the first with both sides attacking with intent but it was West Ham who made the breakthrough after a quick attack was rounded off by Valencia’s first Upton Park goal.
Things were about to get worse for Everton as McGeady, who was booked for a first-half challenge on Matt Jarvis, recklessly brought down Mark Noble and referee Neil Swarbrick had no choice but to show the Republic of Ireland international a second yellow card.
Martinez responded by replacing Ross Barkley and Muhamed Besic with Mirallas and Bryan Oviedo and the move paid off with the fresh legs giving Everton a new lease of life.
Lukaku closed down James Collins’ clearance and with time to pick out a cross he found Mirallas six yards out, but the Belgium international’s shot was miraculously blocked by Tomkins.
However, he wasn’t to be denied for long and he produced a moment of magic from a free kick to beat Adrian from 25-yards out to level the scores with just eight minutes remaining.
The home side thought they should have had a penalty when Valencia’s cross hit Stones on the arm and they had a claim, however Swarbrick adjudged the offence to have been just outside the penalty area.
West Ham had chances to win the game in the dying minutes of normal time but the visitors had Joel Robles to thank for brilliant saves from Kevin Nolan and Collins as the game went to extra time.
Everton thought they had completed the turnaround when Lukaku, who missed a glorious chance minutes earlier, stabbed home Mirallas’ cross.
The visitors then had claims for a penalty turned down when Mirallas was brought down on the edge of the penalty area.
Allardyce threw on Cole for Collins with 10 minutes as he took one last throw of the dice and it proved a masterstroke as the 31-year-old was in the right place at the right time to prod home Tomkins’ knock-down with his first touch of the game.
The two sides could not be separated and the drama continued in the penalty shootout as Mirallas and Noble scored each sides’ first penalties.
Both sides then traded successful attempts until Downing, who stepped up with the chance to win the game, had his kick saved by Robles to send the shootout into sudden death.
However, after another batch of successful penalties from both sides Everton goalkeeper Robles went from hero to zero as he saw his spot kick hit the underside of the bar and bounce out.
Up stepped Adrian to convert his penalty and send jubilant West Ham through to the next round where they will face Bristol City.