Equatorial Guinea pulled off one of the most stunning results in Africa Cup of Nations history on Monday by thrashing hosts Ivory Coast 4-0 to win Group A and secure a last-16 place.
They were joined in the knock-out phase by Nigeria, surprise Group B table-toppers Cape Verde and record seven-time champions Egypt.
Nigeria beat Guinea-Bissau 1-0 to finish runners-up behind Equatorial Guinea and a dramatic 2-2 draw between Cape Verde and Egypt took both through.
Ghana conceded two goals in added time to only draw 2-2 with Mozambique and, with only two points, may not be among the four best third-placed teams that also qualify and could be eliminated on Tuesday.
Ranked 39 places lower than their rivals in the world, Equatorial Guinea ripped the Ivorian defence apart in the second half after leading 1-0 at half-time.
Emilio Nsue took his goals tally to five with a brace and Pablo Ganet and Jannick Buyla also netted for a nation which often boxes above its weight in the tournament, first held in 1957.
“We knew that our opponents were under pressure and we took that into account when putting our strategy in place,” said Equatorial Guinea coach Juan Micha.
“With humility, we are making an effort to reach as far as possible. We are working to reach the level of the big guys.
“Regarding Ivory Coast, I am hurt because it is the organising country, but it is football. We must forget this match and plan for the rest of the competition.”
Ivory Coast coach Jean-Louis Gasset said: “I don’t think it’s because of our state of mind, when I see the players in the dressing room crying, it hurts me.
“We tried, we gave everything I think. When you have a scenario like that, bordering on a nightmare, there’s not much you can say or do.”
Captain Nsue and many of his teammates play in Europe with lower-division clubs.
Equatorial Guinea also make extensive use of the rule that allows footballers with a parent or grandparent born in the central African nation to represent it.
Seventeen of the 27-man squad were born in Spain, including Nsue, whose professional career includes stints in Spain, England, Cyprus as well as Bosnia and Herzegovina.
In three previous appearances, including one as hosts and one as co-hosts with Gabon, Equatorial Guinea have reached the semi-finals once and quarter-finals twice.
Despite that impressive record, they were given little chance against Ivory Coast, widely regarded as one of the favourites to win the African showpiece.
The humiliated Ivorians finished third and could still squeeze into the round of 16 as one of the four best third-placed teams.
They will probably know their fate only on Wednesday after the final group games, and be pinning their survival hopes on wins for Mali, South Africa, Morocco and Democratic Republic of Congo.
Should those four sides secure maximum points, Ivory Coast would probably scrape through to the knockout stage.
There was no hint of the drama to come during the first half with Equatorial Guinea content to sit back and soak up Ivorian pressure that petered out when they came within sight of the goal.
Then, three minutes before half-time, the home crowd were silenced as Nsue, 34, followed up a hat-trick against Guinea-Bissau by putting the National Thunder ahead.
Ibrahim Sangare and Jean-Philippe Krasso put the ball in the net either side of half-time for the home nation, but both goals were disallowed by VAR for offside.
Equatorial Guinea then scored twice within two minutes through Ganet and Nsue to take a three-goal lead and trigger an exodus from the stadium of disbelieving Ivorian supporters.
Ganet brilliantly converted a free-kick from just outside the area on 73 minutes and Nsue fired past goalkeeper Yahia Fofana from close range.
Ivory Coast kept creating and wasting chances before Buyla completed the darkest day in Ivorian football history with an 88th-minute goal.
A spectacular own goal by Opa Sangante on 36 minutes gave Nigeria a 1-0 win over Guinea-Bissau in Abidjan, and second place behind Equatorial Guinea on goal difference.
Mohamed Salah-less Egypt trailed and led against Cape Verde in Abidjan before Bryan Teixeira scored nine minutes into added time to snatch a 2-2 draw for the island nation.