City have now won 10 out of 11 top-flight meetings with the Hammers under the Spaniard.
In a game played in a snow-storm before half-time, skipper Gundogan provided the decisive moment after 33 minutes when he turned home a deflected Riyad Mahrez effort at the far-post.
It was the Germany midfielder's third goal of the season - and his second in four league games - and was followed up in the final minute by Fernandinho, who had only been introduced three minutes earlier to tie the game up.
The veteran Brazilian had not scored a Premier League goal since October 2018 but found the target from the edge of the box.
Manuel Lanzini pulled one back with the final kick of the game, which cost Ederson his 100th clean sheet in all competitions but did nothing to prevent City moving back into second spot, six points clear of the Hammers/
The Londoners remain fourth despite suffering successive Premier League defeats for the first time since April.
City manager Pep Guardiola later said: "Surprised with the amount of chances we created against them. We created a few. The first half was almost impossible to play. The game against PSG was so demanding and the team gave a good performance.
"We have an incredible groundskeeper. Thanks to them we could play.
"The chances we created... it could have been three or four. The players we have out... those that came here were brilliant. All of them. We cannot forget which opponent we played. They have everything."
Need a VPN? Or seeking to switch? Then support Tribal Football by clicking here to sign up with our official partners NordVPN. Not only will you receive the best VPN experience, but also great discounts by signing up via Tribal Football. Thanks for your support!