LYON, France (AP) — Cristiano Ronaldo came through. Twice.
The Portugal winger erupted from his scoring slump on Wednesday, netting his first two goals at the European Championship and putting his team into the round of 16.
Ronaldo's strikes, the first with a spectacular back heel and the second with a header, helped Portugal earn a 3-3 draw with Hungary, sending both teams through.
"Our priority was to win the match. We failed do to that, but we hit the bottom line because we wanted to qualify," Ronaldo said. "I am happy because the team was in dire straits. Three times we were going home and we had to chase down the scoreboard."
The goals came in the 50th and 62nd minutes, and they made Ronaldo the first player to score in four consecutive European Championships.
"This is what Cristiano is all about," Portugal coach Fernando Santos said. "He needs to score because he is a winner and he is a scorer. He feeds on goals."
Portugal ended up with three points in Group F from three draws, advancing as one of the top four third-place teams. The Portuguese will face Croatia on Saturday for a spot in the quarterfinals.
Hungary won the group with five points and will play Belgium on Sunday. Iceland finished the group second with the same number of points, after helping eliminate Austria 2-1 with a 2-1 victory.
After not scoring in his team's opening two draws, the 31-year-old Ronaldo broke out at Stade de Lyon to increase his record haul with his 59th and 60th career goals for Portugal.
"We know he is a world-class player. He is a dangerous player, and you can't always control him," Hungary coach Bernd Storck said. "We didn't give Portugal a lot of chances, but of course when Ronaldo has the ball he can score."
Ronaldo wiped away a week of frustrations in France.
What started with a belittling of Iceland following their draw got worse after he missed a penalty in the stalemate with Austria. The Real Madrid star lost his composure hours before Wednesday's match when he responded to a TV reporter's question by grabbing his microphone and apparently tossing it into a nearby lake.
Ronaldo's on-pitch redemption began after he had again failed to convert a series of free kicks. Instead, he turned playmaker to set up Nani for an equalizer just before halftime, 23 minutes after 37-year-old Zoltan Gera had given Hungary 1-0 lead.
Balazs Dzsudzsak's first of two goals, a deflected free kick, put Hungary back in front in the 47th minute. But moments later it was Ronaldo's turn to get his first goal of Euro 2016.
Dzsudzsak struck again five minutes later with a shot that grazed Nani before looping over goalkeeper Rui Patricio to restore the lead at 3-2. Ronaldo then came through with his second.
"Two of their shots were pure luck, and that will bring any team down," Santos said. "So I would like to praise my players because three times we were out of the next stage."