West Ham goalkeeper Adrian scored the winning penalty as his side beat Everton in a thrilling FA Cup tie.
Enner Valencia put the hosts ahead when he collected Andy Carroll's pass and shot past Toffees keeper Joel Robles.
Everton had Aiden McGeady sent off for two bookable offences, but equalised with Kevin Mirallas's fine free-kick.
Romelu Lukaku put the visitors in front after Mirallas's run, before Carlton Cole's close-range finish took the game to penalties, where West Ham won 9-8.
West Ham United 2-2 (Pen 9-8) Everton All Goals HD paylaşan: sanagoree
The third-round replay had gone to a shootout after it had finished 2-2 at the end of extra time in an amazing match.
But the drama had not finished as Everton's Steven Naismith had his penalty saved and Stewart Downing had a chance to win it for the hosts, but Robles blocked his tame effort.
However, Robles then hit the crossbar with his powerful attempt before Adrian threw off his goalkeeping gloves and calmly converted the 20th penalty to set up a fourth-round tie at League One side Bristol City.
It looked like being a routine win for the Hammers when, leading 1-0, their opponents were reduced to 10 men when McGeady was needlessly sent off after only 56 minutes.
The midfielder had been booked in the first half for a foul on Matt Jarvis before a rash sliding challenge on Mark Noble saw a second caution.
However, Roberto Martinez's side fought back and grabbed a deserved equaliser through substitute Mirallas's powerful free-kick, which curled around the wall and past Adrian.
Robles made excellent saves to deny Noble and substitute Kevin Nolan to take the game into extra time and Lukaku put Everton ahead with a close-range finish after more excellent work from Mirallas.
It was a poignant moment for Lukaku as he raised both arms and pointed to the sky, as a tribute to his friend Junior Malanda, the Belgium Under-21 international and Wolfsburg midfielder who died in a car crash in Germany on Sunday aged 20.
There was then controversy as Everton thought they should have had a penalty when Mirallas was fouled, but the referee gave a free-kick on the edge of the area instead, despite the offence appearing to take place in the area.
But there was still time for another twist as substitute Cole, who had only been on the pitch for two minutes, prodded in James Tomkins's header to take it to penalties.
Adrian proved to be the hero as he saved one spot-kick and scored the decisive one.
West Ham's victory was their first win in the competition since February 2011 and they will now play League One side Bristol City on Sunday, 25 January in a match broadcast live on the BBC.
West Ham manager Sam Allardyce, speaking to BT Sport: "It was an unbelievable match, wasn't it? You can't say the FA Cup has died after that, not with that entertainment value.
"I thought today had absolutely everything a cup tie should have - a little bit of controversy, some great play, chances missed, some great goalkeeping and some very good goals."
West Ham's match-winner Adrian: "It was the most unbelievable game and for the fans I feel really happy.
"I was relaxed and quiet when I struck the penalty and we got the victory and keep going in the FA Cup."
Everton manager Roberto Martinez: "I thought we were the better side. We created really, really good opportunities, and probably we should have taken one or two before the one we scored.
"But in terms of the performance and the character and the phases of good football we showed, I couldn't be prouder.
"Sometimes in football you feel you are going to get what you deserve but clearly today we were unfortunate in the penalty shootout where it is a bit of a lottery."
tags:west ham united vs everton,west ham united vs everton video,west ham united vs everton videos ,west ham united vs everton youtube,west ham united vs everton goals,west ham united vs everton goals preview,west ham united vs everton match video,west ham united vs everton goals video,west ham united vs everton youtube ,west ham united everton goals,west ham united everton goals video,west ham united everton goals youtube,west ham united everton 2015,west ham united v everton,west ham united v everton youtube