Ryan Babel opened his Cottagers account inside three minutes at the London Stadium but the struggling visitor failed to recover after Hernandez's game-changing 29th-minute equaliser.
The Hammers striker's goal-line handball went unnoticed and his side used the lucky lifeline as the springboard to a half-time advantage thanks to Issa Diop's 40th-minute header.
Michail Antonio nodded home the third in the first minute of second-half stoppage time to ensure Claudio Ranieri's side remain eight points adrift of safety.
Babel failed to convert a one-on-one 36 seconds into the match but did not wait long for redemption.
Pablo Zabaleta's weak back-pass gifted away the first chance and he compounded the error by allowing Ryan Sessegnon to deliver the low cross for Babel's first Premier League goal in 3000 days.
The equaliser came steeped in controversy. Antonio and Angelo Ogbonna won headers following Sergio Rico's poor punch before Hernandez guided the ball in with his left hand.
West Ham cared little and scored from a second corner when Diop rose to emphatically meet Robert Snodgrass's delivery.
Marko Arnautovic came on just after the hour before Manuel Lanzini, sidelined since undergoing knee surgery in June, stepped off the bench for his first appearance of the season.
After hitting the upright with one attempt, it was the enigmatic Austria international who supplied the cross for winger Antonio to sew up a first victory in six outings for Manuel Pellegrini's men.