Just as it looked as though the Americans had secured a come-from-behind victory to qualify for the second round, Varela scored with a flying header from a Cristiano Ronaldo cross.
The result means that after two games the U.S. are in second place, level with Germany on four points. Portugal are joint bottom with Ghana on one point and face a tough task to make the next round.
"When you concede in the last second it is unfortunate, but it was an amazing game from us, I can't ask for any more," said U.S. coach Juergen Klinsmann.
The Americans face Germany in the final game and need a point to ensure qualification.
"We will take even more confidence into the next game. It will be another final but that is what the World Cup is about," said Klinsmann.
The U.S. scored late to beat Ghana 2-1 in the first game and Clint Dempsey looked to have repeated the feat in the 81st minute, steering the ball home with his stomach to give his team the lead.
Portugal lost their first game 4-0 to Germany and coach Paulo Bento said his team had to beat the Americans to stand any chance of progressing.
Portugal opened the scoring in the fifth minute when U.S. defender Geoff Cameron swung a foot at a Miguel Veloso cross and succeeded only in slicing the ball across his own area right to the feet of Nani, who scored easily.
The Europeans then sat back in the heat and humidity, allowing their opponents to start dominating. The temperature in the Amazonia arena was 30 degrees Celsius (86 Fahrenheit) at kickoff with a humidity reading of 65 percent.
Portugal still looked dangerous in the first half and Nani hit the left-hand post in the 45th minute from outside the area. The ball rebounded to Eder but his looping shot was brilliantly scooped over the bar by U.S. goalkeeper Tim Howard.
As the second half progressed the Portuguese wilted and it was little surprise when U.S. midfielder Jermaine Jones cut in from the left in the 64th minute and fired in a superb right- foot curling shot from 25 metres to equalise.
Portugal started with Ronaldo, who has been trying to shake off a knee injury. He was ineffective against the Germans and only shone fitfully against the Americans, leaving the best until last.
The U.S. missed a great chance to equalise in the 55th minute when Michael Bradley's close-range shot was cleared off the line by Ricardo Costa.
Varela's goal was the second time he has struck late for Portugal at a major tournament. In Euro 2012, he scored an 87th-minute winner against Denmark in a first-round game.