Gray, one of nine new faces in a much-changed Foxes line-up, fluffed the opportunity to open his Premier League goal account for the season from the spot after only 12 minutes.
But the winger made amends after the interval to fire second-placed Leicester to a first league win in four games while inflicting a fourth straight home defeat on woeful West Ham, who have won just twice in 14 matches.
The natives are getting increasingly restless at the London Stadium, and Pellegrini’s decision to substitute record signing Sebastien Haller, rather than give him some support in attack, was met with loud jeers.
Captain Mark Noble, who had an on-field bust-up with Angelo Ogbonna at Crystal Palace on Boxing Day, was dropped to the bench, while the Italian defender was not even named in the squad.