PARIS (AP) Cristiano Ronaldo dragged Portugal back from the brink of elimination twice, and Ireland found a late goal to stun Italy and stay in the European Championship on Wednesday.
Iceland's winning goal in stoppage-time against Austria wrote another chapter of the tournament's feel-good story and set up a round of 16 clash with England.
Belgium, widely seen as a potential champion, confirmed its place in the supposedly easier half of the knockout bracket by beating Sweden 1-0. The victory also signaled the start of Zlatan Ibrahimovic's retirement from the Swedes' national team.
Sweden and Austria are heading home now, as are Turkey and Albania, which had hung around in France hoping that results would fall their way and lead to a place in the last 16 among the best third-placed teams.
Those hopes were dashed on Wednesday.
Portugal and Ireland earned the final two slots on a day of wildly swinging fortunes and emotions.
Ronaldo showed an array of anguished expressions and gestures as Portugal, needing at least a draw to advance, trailed three times to a Hungary side that already was sure to advance - yet sought to top Group F.
First, Ronaldo created one equalizer for teammate Nani, and then he scored two himself in the second half - the first with an audacious flick of his right heel - as a thriller ended 3-3 in Lyon.
''This was an insane match. Three times we were going home,'' said Ronaldo, who set an all-time European Championship record of scoring in four different editions.
With one more goal when Portugal plays Croatia on Saturday in Lens, Ronaldo will tie Michel Platini's career scoring record of nine goals at European finals tournaments.
Ronaldo seemed destined for yet another knockout encounter with old rival England until Iceland's Arnor Ingvi Traustason scored in the last of four added minutes. Now Nice will welcome Iceland to play the English on Monday.
If Iceland and its happy fans have become many neutrals' favorite team at Euro 2016, they have taken a role Ireland has had at previous major tournaments.
Ireland delighted its passionate throng of green-clad fans in Lille when Robbie Brady headed an 85th-minute goal to win 1-0 against Italy, which already was sure to top Group E.
Until that moment, Ireland was going home and Turkey was set to get one of the third-place slots.
Ireland's reward is some unfinished business with France in Lyon on Sunday. When last they met, in a playoff to qualify for the 2010 World Cup, a notorious handball by France striker Thierry Henry led to the decisive goal in extra time at Stade de France.
Other round of 16 fixtures slotted into place only when the group-stage was completed Wednesday.
Northern Ireland now knows it will play group winner Wales in a British derby match in Paris on Saturday.
Two-time defending champion Spain, World Cup holder Germany, host France, Italy and England are all in the same half of the draw.
Round of 16 draw:
Saturday: Switzerland vs. Poland (Saint-Etienne, 3 p.m.) Wales vs. Northern Ireland (Paris, 6 p.m.), Croatia vs. Portugal (Lens, 9 p.m.)
Sunday: France vs. Ireland (Lyon, 3 p.m.), Germany vs. Slovakia (Lille, 6 p.m.), Hungary vs. Belgium (Toulouse, 9 p.m.)
Monday: Italy vs. Spain (Saint-Denis, 6 p.m.), England vs. Iceland (Nice, 9 p.m.).