Updated

Portugal's hopes of reaching the knockout round at Euro 2012 got a massive boost from Silvestre Varela on Wednesday as he came off the bench to net the winning goal in the 87th minute of a 3-2 win over Denmark in Group B play.

Portugal appeared to be in control of the game through the first 35 minutes as goals from Pepe and Helder Postiga put the Portuguese up 2-0.

However, Denmark responded through Nicklas Bendtner shortly before halftime, while Bendtner scored again 10 minutes from time to put Denmark in position to steal a point.

Varela nearly came off the bench to score in the final minutes against Germany in Portugal's opening match, only to be denied at close range by German goalkeeper Manuel Neuer.

But he made sure to beat Denmark netminder Stephan Andersen on Wednesday, moving Portugal level with the Danes on three points and very much in the hunt for a place in the next round.

Portugal had the better of the play for most of the first half and went in front after 24 minutes as Joao Moutinho drove a corner kick to the near post that Pepe turned past Andersen with a well-directed header.

The lead was doubled 10 minutes before the break when Nani picked out a cutting Postiga with a nice pass, allowing the striker to smash a first-time shot into the back of the net from seven yards.

The Danes hardly managed to test Portugal goalkeeper Rui Patricio, but they pulled a goal back four minutes before halftime when Michael Krohn-Dehli got to the back post and nodded the ball back across the face of goal, leaving Bendtner to head the ball into an empty net from close range.

William Kvist nearly equalized for Denmark in the 62nd minute when he sent a screaming shot wide of the post, while Cristiano Ronaldo squandered a golden chance to add to Portugal's lead.

A brilliant ball from Nani played the Real Madrid man in on goal, but with just Andersen to beat, Ronaldo pushed his shot wide.

Bendtner then made him pay two minutes later when he headed home Lars Jacobsen's right-wing cross, pulling Denmark level.

But just when it seemed as though Portugal would need a miracle on the final day of group play to advance, Varela came up with some late heroics as he got on the end of a cross from Fabio Coentrao to fire home the winning goal just three minutes after entering the match.

The result sets up an interesting final day in Group B as Portugal will face the Netherlands while Denmark takes on Germany.