Portugal's Silvestre Varela scored a dramatic 87th-winner to give his side a 3-2 win over Denmark in a pulsating Euro 2012 Group B match on Wednesday.
Portugal looked to have thrown a two-goal lead away when Danish striker Nicklas Bendtner scored the second of two close-range headers to equalise in the 80th minute.
But Varela gave the Portuguese the win they badly needed when he smashed home from close range.
Portugal had taken a 2-0 lead in the first half after good work by Nani. Defender Pepe lost his marker from a corner and powered a header past keeper Stephan Andersen in the 24th minute.
They doubled their lead in the 36th minute when striker Helder Postiga got in front of defender Simon Kjaer far too easily to turn home a Nani pass from close range.
It was a bad moment for Kjaer, who had boasted Denmark would be able to contain winger Cristiano Ronaldo, and he had to make a desperate clearance in the 44th minute to stop Nani setting up another goal.
Bendtner scored his first in the 41st minute, nodding home after Michael Krohn-Dehli sent a looping header over keeper Rui Patricio. The goals were his fourth and fifth in four competitive games against Portugal.
The result means Denmark and Portugal both have three points with one game left. Leaders Germany and the Netherlands play later on Wednesday.
Ronaldo had another poor game and missed two good chances, shooting straight at Andersen in the 50th minute and screwing a shot wide in the 78th when it looked easier to score.
Denmark have a good recent record against Portugal but looked largely toothless and it was little surprise when Portugal, who had lost three consecutive European Championship games, took the lead.
Pepe was their best player in the 1-0 defeat by Germany last Saturday and looked good again.
The Danes, who had defended brilliantly in their opening 1-0 win over the Dutch, were not helped by the loss of midfielder Niki Zimling and winger Dennis Rommedahl to injury.
Photograph: Gleb Garanich / Reuters