Jesse Lingard took the lead in the 29th minute, and Lingard came back and added the second goal in the 44th minute.
In the 48th minute, Jarrod Bowen scored the third goal for West Ham.
But Clichy Iheanacho scored the goal to reduce the deficit in the 70th minute.
Iheanacho added the second goal for his team in the 91st minute.
The West Ham victory raised its score to 55 points to return to fourth place, reducing the difference between it and Leicester City to only one point, with the Foxes occupying third place with 56 points.
The match was the 400th for Mark Nobel with West Ham, to be the eighth in the history of the Premier League to reach this number of matches with one team.
Lingard continued his brilliance with West Ham, since his move to the team, he has become more than one in the league goals with 11 goals, after he scored 8 goals and made 3.
Lingard also became the most prolific league record since his debut for West Ham.
He became the third player to score in 4 consecutive matches for a team coached by David Moyes, after Mikel Arteta with Everton and Robin Van Persie with Manchester United.
Lingard equaled his best goalscoring season with Manchester United (8 goals in 33 games), after he reached his eighth goal in just 9 games with West Ham.
On the other hand, Iheanacho continued to shine.
The Nigerian striker has scored 7 goals in his last 5 matches with Leicester City.
West Ham will play Newcastle United in the next round, while Leicester City will play West Bromwich Albion.