Cristiano Ronaldo set up Varela for a late equalizer on a hot and humid night in the jungle to give Portugal a 2-2 draw with the United States and hope for a spot in the second round of the World Cup.
Ronaldo, who has been playing despite a left knee injury, sent in a cross in the fifth minute of stoppage time and Varela scored with a diving header in the last seconds of the match.
Nani had scored first for Portugal, shooting past a sprawling Tim Howard in the fifth minute, but the Americans responded in the second half as Portugal seemed to wilt in the stifling heat.
Jermaine Jones made it 1-1 with a curling shot in the 64th minute after a cross from Graham Zusi made its way through the Portugal defense.
Clint Dempsey, playing with a broken nose, then put the Americans ahead in the 81st minute. The United States captain used his stomach to direct the ball into the net from a cross by Zusi.
The last-second draw denied the Americans a spot in the second round, but it kept Portugal alive in the tournament.
The Americans will face Germanyin Recife, while Portugal takes on Ghana at the same time in Brasilia.