Varela scored from short range three minutes after coming on as a substitute in the 84th minute, helping the Portuguese bounce back from a 1-0 loss to Germany in their opening game.
The Portuguese left it late, however, and looked like they would have to settle for a draw after Nicklas Bendtner leveled the score with his second goal in the 80th.
"Conceding an equaliser so late, we showed great strength of character to keep going after the win," said Portugal coach Paulo Bento, whose team refound its goalscoring form after a four-game winless streak when it found the net only once.
Pepe gave Portugal the lead with a header in the 24th and Helder Postiga added another in the 37th. But Bendtner scored in the 41st when he headed into an open goal after Michael Krohn-Dehli headed across the goal from the back post.
Bendtner has scored in each of the four official games he's played in against Portugal. Cristiano Ronaldo had another miserable game, squandering two clear chances in front of Denmark goalkeeper Stephan Andersen and bringing jeers from the crowd.
"We should have killed the game off earlier," Bento said. "We had enough chances."
The loss was a setback for Denmark's ambitions after it beat the Netherlands 1-0 in its opening game. Both Portugal and Denmark now have three points in Group B.