Citizens boss Pep Guardiola made four changes, with Eliaquim Mangala, Danilo, David Silva and Leroy Sane handed starts, with Vincent Kompany among those to drop out.
The Hammers named Adrian in goal, with loanee Joe Hart unable to feature against his parent club, with the injured Winston Reid, Marko Arnautovic and Andre Ayew also missing out.
The hosts dominated the early possession, with the Irons defending deep and in numbers, although eight minutes in Michail Antonio almost touched home a Hammers corner which had been flicked on to the far post.
City continued to press and probe, but were unable to forge a clear opening in the opening 20 minutes of the game.
A deflected David Silva drive forced then forced a fine fingertip save from Adrian, before Raheem Sterling drilled a 20-yarder high and wide.
City then had a scare ten minutes before half-time as keeper Ederson had to block a Manuel Lanzini drive at his near post.
And they failed to heed that warning as a minute before the interval Aaron Cresswell swung over a ball from the right and Angelo Ogbonna rose highest to power home a header which Ederson could not keep out.
The Citizens brought on Gabriel Jesus at half-time in response to being behind and 11 minutes into the second half Adrian made a fine save to keep out a Kevin De Bruyne free-kick.
However, he was beaten less than a minute later as Jesus found space to cross from the right and Nicolas Otamendi was in the right place to bundle the ball home from close range.
Sane was next to test Adrian with a drive from the left side of the area, while David Silva sent a 30-yarder over the top as the visitors started to tire.
Adrian was called 20 minutes from time to tip away a Jesus curler, with Sterling somehow managing to fail to sidefoot home the rebound.
A rare counter saw Antonio extend Ederson with a long-range effort, before City finally found a winning goal seven minutes from time. De Bruyne curled a delicious ball to the back post and Silva found the net with an expertly-taken left-foot volley.
There was still time for Diafra Sakho to flash a shot narrowly wide to give the Citizens a late scare, but they held on for all three points.