Sergio Aguero's winner in the dying seconds rescued Manchester City as they came from behind to claim their first Champions League win.
Roberto Mancini's side looked set for more frustration after Villarreal belied their poor La Liga form to leave City on the brink of a third game without victory in the group stage.
Cani had set the tone for an uncomfortable evening when he gave Villarreal the lead after only four minutes and City's only response was an own goal from Carlos Marchena just before the interval.
But deep into stoppage time, and with what turned out to be almost the final kick of the game, substitute Aguero arrived at the far post to turn Pablo Zabaleta's cross past Diego Lopez to revive City's hopes of reaching the knockout phase.
A draw would not have been fatal for City, but it would have left them with a tough task after drawing with Napoli at the Etihad and losing to Bayern Munich in Germany.
And it was left to Argentine Aguero, on as a second-half substitute, to come to City's rescue with a poacher's finish that left Villarreal devastated that such a fine performance had left them empty-handed.
It also came as sweet relief to Mancini after City's off-colour display saw him replace Adam Johnson with Gareth Barry after only 39 minutes, much to the player's obvious displeasure.
Mancini had to deal with Edin Dzeko's unhappiness at being substituted and the Carlos Tevez affair in Munich - but this just appeared a case of genuine disappointment from Johnson.
All this was forgotten as City's players celebrated at the final whistle in the hope that this dramatic finale will see their Champions League campaign now gather momentum.
Mancini made it clear before kick-off that victory was the only priority - no matter how it was achieved after picking up only one point from their opening two games.
City made the worst possible start, however, as they fell behind in the fourth minute. The normally impeccable David Silva conceded cheap possession and when keeper Joe Hart could only push out former Manchester United striker Giuseppe Rossi's shot Cani was able to turn in the rebound.
The goal was greeter in virtual silence, a mixture of stunned City fans and the fact that Villarreal had only brought a tiny band of travelling fans to Manchester.
City attempted to build momentum with Aleksandar Kolarov prominent, forcing Lopez into a smart save from an angled free-kick and sending another long-range effort flashing across the face of goal.
As the home fans grew more impatient, Mancini illustrated the scale of his concern by making the tactical substitution six minutes before the interval - a decision that saw the England winger depart shaking his head.
The mood of discontent was swiftly replaced by delight as City drew level after 43 minutes. Kolarov was again involved with a cross that was destined for Dzeko, only for Marchena to get their first and turn the ball into his own net.
Dzeko's performance had left much to be desired, but he could have made amends two minutes after the restart when Zabaleta found him unmarked in the area. He found the target but Lopez made a fine diving save.
Rossi had looked a class act throughout and he gave Hart another moment of anxiety after 51 minutes when he could only push his shot away and fortunately for City there was no-one from Villarreal on hand to take advantage.
Mancini made another change after 62 minutes when Aguero, now recovered from a groin injury, came on for Nigel de Jong.
Villarreal were keeping City at arm's length with very few alarms, comfortable in possession and with a simple approach that was serving them well.
City were unable to build up any pressure, although they did carve out a clear chance with four minutes left, only for Dzeko to direct Kolarov's inviting cross tamely wide.
Zabaleta also wasted a headed chance but then played a crucial part in that dramatic climax. His cross was touched on by Silva and Aguero arrived to score.
There was barely time to kick-off and a scene of total frustration had been instantly transformed into one of celebration.