Wimbledon may be bottom of League One, and 58 places adrift of the Hammers, but that didn't stop them being 3-0 up early in the second half, with Scott Wagstaff scoring twice after Kwesi Appiah's opener.
Hammers substitutes Lucas Perez and Felipe Anderson scored to make it 3-2, before Wimbledon's Toby Sibbick, not even born when the club won the 1988 FA Cup final against Liverpool, headed in the winner two minutes from time.
The Hammers were not the only top-flight side beaten by lower league opposition, with Everton losing 3-2 to Millwall in controversial fashion earlier in the day.
League One Shrewsbury, who play in the same division as AFC Wimbledon, came close to a Cup shock of their own before Wolves scored a 93rd-minute equaliser to rescue a 2-2 draw at New Meadow.
Meanwhile, Manchester City's quest for four trophies continued with a 5-0 thrashing of Burnley.
AFC Wimbledon, formed by fans angry when the old Wimbledon FC was effectively relocated from south London to Milton Keynes, took a deserved lead in the 34th minute through Appiah's deflected shot from the edge of the box.
And they were 2-0 up before the break.
Wagstaff ran all the way to the edge of the box unopposed after dispossessing Pedro Obiang on halfway before calmly slotting the past Hammers keeper Adrian.
Then just seconds into the second half, Wagstaff made it 3-0 when, following an Apppiah cross, he scored from 12 yards.
Perez pulled one back in the 57th minute and before Anderson's free-kick raised hope of a Hammers equaliser
But teenage substitute Sibbick then headed in an excellent cross from Anthony Wordsworth to put the result beyond doubt.
"Today's performance shows that we can do it and hopefully now we can pick up some results (in the league). The boys were excellent and worked their socks off all game," Wagstaff told BT Sport.
Silva bemoans lack of VAR
Everton twice led at The Den, but were left to rue the lack of VAR at the game as Millwall's second goal, from Jake Cooper, was allowed to stand despite coming off the defender's arm.
However, Marco Silva's men only had themselves to blame after dire defending saw them concede from three set-pieces.
Richarlison's long range effort squirmed through Jordan Archer's grasp to give the visitors a lead that lasted just four minutes when Lee Gregory's header levelled in first-half stoppage time.
Substitute Cenk Tosun restored Everton's advantage before the moment of controversy when the ball ricocheted off Cooper's arm and into an unguarded net.
But with VAR not in use, referee Michael Oliver had to uphold his original decision to give the goal despite Everton's furious protests as the incident was replayed on the big screen.
Worse followed for the Toffees, when Murray Wallace turned home another free-kick into the box in the 94th minute.
"If the competition has VAR for some stadiums then it has to have it in all," said Silva. "Because it doesn't make sense. It was a clear handball."
City boss Pep Guardiola labelled talk of a quadruple as "fantasy" earlier in the week but, after Saturday's performance, Burnley manager Sean Dyche said: "Who is going to stop them winning everything if they are in that mood?"
Goals from Gabriel Jesus, Bernardo Silva and Kevin De Bruyne left City on top before Kevin Long's own-goal and Sergio Aguero's penalty completed the rout.
Wolves knocked out Premier League leaders Liverpool in the last round, but needed a late fightback from 2-0 down to force a replay at Shrewsbury.
Greg Docherty fired Shrewsbury into the lead just two minutes into the second-half before Luke Waterfall's towering header made it 2-0.
Raul Jimenez came off the bench to give the Wolves a lifeline and Matt Doherty equalised three minutes into stoppage time.
Watford won an all-Premier League tie despite Javi Gracia making 11 changes as Andre Gray and Isaac Success scored in a 2-0 victory at Newcastle.
Newport County's fairytale continued as the League Two side, who beat Leicester in round three, equalised in stoppage time to earn a 1-1 draw at Middlesbrough.
Frank Lampard's Derby County moved into the last 16 with a hard-fought 1-0 win at League One Accrington Stanley as both sides ended with 10 men.