City had a chance early on when David Silva slipped through Alvaro Negredo, but instead of shooting, the Spaniard tried to square the ball for Aguero, allowing Winston Reid to get a block in.
The Hammers could not repel the visitors for much longer, with Negredo showing great awareness to let Yaya Toure's pass run through for Aguero to slot past Jussi Jaaskelainen after 15 minutes.
Ricardo Vaz Te could have levelled matters had he got hold of his volley from Guy Demel's cross, but City escaped and could have gone 2-0 ahead through Negredo five minutes later.
Sam Allardyce's men trailed by one goal heading into the break but slack defending from a set piece allowed Aguero the simplest of headers to double the deficit five minutes after the restart.
Just as City threatened to run away with the match, West Ham struck back with a brilliant overhead finish from Vaz Te.
Negredo struck the bar from a tight angle on the hour mark as Pellegrini's men went looking for a third, but they found their way through again 10 minutes before the end when Silva curled beyond a despairing Jaaskelainen.