Nigel Pearson's side picked up their first Premier League win since January as they move to within four points of safety with eight games left to play
The hosts' first league victory since January sees them move to within four points of safety, with Esteban Cambiasso's superb volley having initially put them ahead at the King Power Stadium.
David Nugent missed the chance to double the advantage three minutes later when he saw a penalty saved by Adrian after Leonardo Ulloa was felled by Carl Jenkinson in the area.
It appeared as though that would prove costly as West Ham deservedly levelled before the break through a well taken half-volley from Cheikhou Kouyate.
However, Leicester were the better side after the break and earned a crucial three points when King, who had only been on the pitch seven minutes, scored from close range in the 86th minute.
Nugent combined with Ulloa before the ball cannoned off James Collins and sat up perfectly for Cambiasso, who guided a superb left-footed volley in to the bottom right-hand corner from 25 yards.
The hosts, who brought in Riyad Mahrez for Matthew Upson, had a great chance to go two up when Jenkinson was penalised for a clumsy sliding challenge on Ulloa in the penalty area.
However, Nugent fluffed his lines from 12 yards as Adrian flung himself low to the left to make the save.
West Ham, who welcomed Winston Reid back from a hamstring injury in place of Matt Jarvis, grew into the match and Kevin Nolan was guilty of missing a free header from eight yards.
The pressure told in the 32nd minute when Alex Song's exquisite chipped pass was too high for Jeffrey Schlupp and Kouyate controlled the ball on the right of the area before finishing emphatically into the far corner.
Leicester started well after the break and Schlupp should have done more to test Adrian on the hour mark when he slashed wildly wide after being teed up by Nugent.
West Ham were on the back foot and Jamie Vardy headed wide from eight yards when Ritchie De Laet's long throw was flicked on by Ulloa, before the forward fired a left-foot shot from the edge of the penalty area wide.
Leicester were nearly made to pay for their profligacy as Kouyate's low effort from an acute angle rebounded off the woodwork.
Both teams had chances to win it in a frantic ending and substitute Andrej Kramaric had a shot cleared off the line before was Leicester made the breakthrough.
West Ham failed to deal with a goalmouth scramble and King got the final touch to send the ball over the line - much to the delight of the home faithful.