Manchester United came from a goal down to beat Braga 3-1 and book their spot in the last 16 in a UEFA Champions League Group H game disrupted by floodlight failure.
Sir Alex Ferguson's men needed just a point from the trip to Portugal on Wednesday to advance to the knockout rounds but went one better as they made it four group wins from four.
Alan's scored a 49th-minute penalty after Jonny Evans had brought down Custodio to put Braga ahead and that spot-kick was followed by a 12-minute break as the Estadio AXA floodlights failed to leave the pitch in darkness.
But United came to life after the restart as substitute Robin van Persie netted an 80th-minute equaliser before Wayne Rooney converted from the spot after a Douglao challenge on Chris Smalling and Javier Hernandez scored at the death.
Braga had caused United plenty of problems early on at Old Trafford last month, racing into a 2-0 lead inside the opening 20 minutes before eventually going down 3-2, and in the spectacular surroundings of the Estadio AXA the Portuguese side once again had made the better start.
The Red Devils were unable to fashion much from their early possession, but did register an effort on goal on the half-hour mark when Evans' tame header from Antonio Valencia's cross was easily caught by home goalkeeper Beto.
Braga were soon back on the attack, with Alan drilling low into David de Gea's arms, and the Spaniard then gathered a free-kick from Viana on his line after the fit-again Chris Smalling - making his first appearance of the season - had been booked for fouling Eder.
Nani nodded goalwards from another Valencia cross just before the interval, but again it did little to trouble Beto.
Four minutes into the second half, United were behind after Custodio collided with Evans in the box. The referee pointed to the spot and Alan - who had scored Braga's two goals in the reverse fixture last month - made no mistake, smashing the penalty into the roof of the net.
As United looked for a response, a power cut at the stadium saw some of the floodlights go out and play was suspended for around 12 minutes.
United boss Sir Alex Ferguson used the unscheduled break to substitute Evans for Rio Ferdinand and after play resumed, De Gea got down to push away a free-kick by Nuno Coelho.
Ferguson swiftly made further adjustments, introducing Van Persie for Danny Welbeck and Rafael for Nani.
The reshuffle certainly had the desired effect, with Van Persie notching his 11th goal of the season with 10 minutes of normal time remaining, the Dutchman expertly guiding the ball over Beto, who had rushed out too soon and was attempting to get back to his line.
Rooney was then brought down in the box by Nuno Coelho and, having taken his time to decide, the referee again awarded a penalty. Unlike against Arsenal, the England forward converted his spot-kick to hand United the advantage, and Hernandez completed the turnaround at the death, prodding the ball in at the second attempt after his initial shot had been blocked on the line.