Cristiano Ronaldo came to Portugal's rescue with two penalties to cancel out a brace from France's Karim Benzema in an enthralling 2-2 draw that sent both sides into the Euro 2020 last 16 in a frantic conclusion to Group F on Wednesday.
An anxious night for the reigning European champions saw them occupy every position in the so-called group of death at various junctures but the 36-year-old Ronaldo, so often his country's saviour, stepped up to reach another career milestone.
He had already become the highest-ever scorer in Euro finals with his double against Hungary in the opening game and his two spot-kick conversions -- in the 31st and 60th minutes -- took him to 109 international goals, level with the record number scored by Iran's Ali Daei.
Benzema's first was also from the spot as for the first time in European Championship history three penalties were converted in regular time.
The Frenchman, recalled by manager Didier Deschamps for the tournament after a five-year exile, equalised on the stroke of halftime with his first France goal for five years and 258 days.
He put France ahead two minutes after the interval and with Hungary leading Germany at that point in the other game, Portugal were bottom of Group F and staring at the exit.
But Ronaldo coolly beat Hugo Lloris again from 12 yards and Portugal held on for the draw which means they finished on four points in third place and can now prepare for a last-16 clash against Belgium in Seville.
World champions France topped a crazy group with five points and will take on Switzerland in Bucharest.
"It was a fight and it wasn't easy. We gave them the two goals from mistakes. We tried to win it," said France manager Didier Deschamps, whose side were in danger of a last-16 clash with England at Wembley when they fell behind.
"It means we're top and that's the best position."
EVERY SCENARIO
The Euro 2020 format has been criticised but there is no doubt that it produced a gripping night in which every conceivable scenario seemed to come into play.
Portugal needed only a draw to seal a last-16 spot but after bossing the first half with recalled Renato Sanches and Joao Moutinho commanding in midfield, they lived dangerously.
When the dust settled however, they will be in the business end of the tournament they won in 2016 by beating France.
Manager Fernando Santos was impressed with the way his side rebounded after the 4-2 defeat by Germany.
"When I was asked what we had to do that was different from the game against Germany and I said it was to be like ourselves," he said. "We were strong, consistent, with a great spirit. We can continue to improve."
Portgual were awarded a penalty in the 27th minute after Hugo Lloris's attempted punched clearance wiped out Danilo. Lloris was shown a yellow card before Ronaldo smashed the penalty into the corner.
Portugal began to swagger but they were pegged back when referee Antonio Mateu Lahoz deemed that Nelson Semedo had bundled over Kylian Mbappe on the stroke of halftime as he tried to latch on to Paul Pogba's pass.
Benzema buried the penalty and two minutes after the break he was picked out by the influential Pogba again and the Real Madrid striker slotted the ball past Rui Patricio.
But the game's third penalty, awarded for a handball by Jules Kounde, gave Ronaldo the chance to beat Lloris again from the spot to register his fifth goal of the tournament and he was never going to miss.
Rui Patricio turned a spectacular Pogba effort against the woodwork seven minutes later but Portugal held on and got the added bonus of a late Germany equaliser that means they also avoided a last-16 meeting with England.