Published: 2017-03-19 11:01:48 BdST
Shakespeare's fourth successive victory in all competitions since he took over from title-winning manager Italian Claudio Ranieri last month left Leicester in 15th position on 30 points from 28 games, six above the relegation zone.
"We needed something from today to go into the international break," Shakespeare said after seeing his side hang on in a frantic finale, having been rescued by some fine goalkeeping from Kasper Schmeichel.
"Kasper made some big saves but he's the first to say that's what he's there for.
"We can't get carried away. It's three Premier League wins but it's feet firmly on the ground."
Still buzzing after a shock 3-2 aggregate midweek win over Spanish side Sevilla in the Champions League last 16, Leicester stunned West Ham with two goals in the opening seven minutes.
Riyad Mahrez fired them ahead after five minutes with a cross which eluded everyone in the penalty area and deceived goalkeeper Darren Randolph before Robert Huth headed the second two minutes later after a lovely Marc Albrighton cross.
Manuel Lanzini hauled the home side back into the contest in the 20th minute with a superb free kick into the top right corner from 22 metres but their joy was short-lived as Jamie Vardy made it 3-1 with an opportunist goal before the interval.
The Foxes were on the back foot after forward Andre Ayew headed in West Ham's second, with the home side laying siege to Leicester's goal in the last 25 minutes.
Schmeichel produced two stunning saves to deny Andy Carroll while Ayew blasted over from seven metres with the goal at his mercy.