The decisive moment came in the 59th minute when Felipe Anderson was ruled to have brought down Bernardo Silva and Aguero coolly slotted home from the spot.
Former City manager Manuel Pellegrini set his West Ham team up to frustrate the hosts and they did an excellent job for most of the game.
The Hammers forced City into wide areas where they struggled to create openings.
City camped in the visitors’ half for the opening 45 minutes with David Silva going close to breaking the deadlock when he hit the post after an excellent low cross.
West Ham went close after the break when substitute Manuel Lanzini found Andy Carroll at the back post, but City keeper Ederson did well to parry the forward’s well-struck effort.
City boss Pep Guardiola promptly threw on Raheem Sterling and Bernardo Silva from the bench and they changed the tempo and flow of the game.
Second-placed City have 68 points while leaders Liverpool are on 69. (Reuters/NAN)