Aguero tapped home with virtually the last kick of the game just as the Spanish side looked to have lengthened City’s wait for their first win in the competition.
Villarreal had stunned Roberto Mancini’s men by taking a fourth-minute lead through Ruben Cani but a Carlos Marchena own goal hauled City back onto level terms just before the break.
For much of the second half City were laboured but fit-again Aguero, who came off the bench on the hour, earned his side their first win in Group A.
City recovered from the shock of conceding early to dominate first-half possession but, despite the constant probing of David Silva, they lacked their usual Premier League swagger.
It had seemed the return of Silva, Samir Nasri and Edin Dzeko, all rested at the weekend, had failed to find the winning formula in Europe.
And after the well-documented problems with substitutions in the loss to Bayern Munich last month, Mancini appeared to upset another player by taking Adam Johnson off late in the first half.
City had gone into the game as clear favourites but it was La Liga’s 13th-placed side who made the perfect start.
The game had barely begun when when Silva played Nigel de Jong into trouble outside his own area and Jonathan de Guzman nipped in to steal possession.
Former Manchester United striker Giuseppe Rossi, a constant menace, lashed a shot at goal that Joe Hart could only parry and Cani reacted quickly to poke home.
Villarreal were lifted by that first goal in this season’s group stages and Joleon Lescott needed to break up another promising attack.
After that sloppy start, City finally began to find some life after Aleksandar Kolarov, scorer of the equaliser against Napoli earlier in the competition, fired wide from distance.
Kolarov then found space on the left to clip in a cross for Nasri on the edge of the box but the Frenchman volleyed narrowly over.
Kolarov went for goal direct from a free-kick but goalkeeper Diego Lopez palmed his curling effort away.
With Silva influential, City looked to maintain the pressure but, after a good spell, found Villarreal difficult to penetrate.
Nasri did find a way through after exchanging passes with Silva but fired a low cross straight through the area.
Yaya Toure pounced on a mistake to surge forward but shot way off target and a Kolarov cross proved too strong for Pablo Zabaleta.
Mancini surprisingly made a change five minutes before the break by sending on Gareth Barry for Johnson, who was not injured and shook his head as he left the field.
Although the change itself made little difference to City’s overall play, Barry was involved in the build-up as the hosts pulled level three minutes later.
Kolarov made another incisive run and his low cross took a slight deflection before a sliding Marchena diverted it into his own goal attempting to clear.
City almost snatched the lead before the break when Silva played in Dzeko but Lopez reacted quickly to save.
City were almost caught napping at the restart as Rossi robbed Vincent Kompany and blasted a shot wide after a dangerous run.
The hosts responded as Silva spread the ball wide for Zabaleta and his cross dropped nicely for an onside Dzeko but the Bosnian failed to make clean contact and Lopez saved.
City thought they had claimed the lead after 54 minutes when Kolarov smashed in a shot off the underside of the bar but the flag was raised for offside.
Villarreal gave City another scare just before the hour when former West Brom midfielder Borja Valero found space to shoot but missed the target.
Cristian Zapata also stretched City on the counter-attack but did not trouble Hart.
With City looking leaden-footed, Mancini made a second substitution with Aguero replacing De Jong.
Rossi, who had caused City a number of problems with his pace, threatened again but was booked on the edge of the area for diving after minimal contact with Kompany.
Kolarov got another chance from a free-kick but, from a similar position to where he scored against Napoli, this time shot the wrong side of the post.
City fans had been handed out sheets of paper to form a mosaic prior to kick-off but their frustration was evident when Valero was pelted with a paper ball taking a corner late on.
Dzeko had a chance in the closing minutes but his frustrating evening only continued as he headed well wide.
Zabaleta had an even better opportunity but headed tamely at Lopez.
Just as time looked to be up, Zabaleta crossed and Aguero tapped in to spark jubilant scenes.