Cairo - Tunisia and South Africa filled the final two places in the Africa Cup of Nations (AFCON) last-16 draw on Tuesday after a tense finish to the group stage in Egypt.
Already-qualified Mali defeated Angola 1-0 in Ismailia through an Amadou Haidara thunderbolt to win Group E and eliminate the losers from the competition.
Tunisia, ranked second in Africa behind Senegal, could only draw 0-0 with debutants Mauritania in Suez but the point secured second place behind Mali.
Mali won the group with seven points followed by Tunisia with three and Angola and Mauritania with two each.
Angola losing meant South Africa sneaked into the knockout phase, joining Guinea, the Democratic Republic of Congo and Benin as the best four third-place teams.
Mali will face the Ivory Coast in the round of 16 while Tunisia meet Ghana, who are chasing a seventh consecutive top-four finish in the Cup of Nations.
Highlight of the round is the clash of defending champions Cameroon and Nigeria, who have won the competition eight times between them.
Hosts Egypt, Algeria and Morocco, the three countries who finished first in groups with perfect three-win records, all face opponents who came third.
Mohamed Salah-inspired Egypt meet South Africa in a fixture sure to fill the 75 000-capacity Cairo International Stadium this Saturday.
Morocco face Benin in Cairo Friday in the first of the eight last-16 fixtures and Algeria tackle Guinea Sunday, also in the Egyptian capital.
Fairytale qualifiers Madagascar stay in Alexandria, where they stunned three-time former champions Nigeria to win Group B, for a showdown with DR Congo.
Boosted by a Sadio Mane brace against Kenya, Senegal will face another east African nation, Uganda, for a quarter-finals place.
In Ismailia, Mali made eight changes from the team that drew against Tunisia with captain Abdoulay Diaby and ace striker Moussa Marega among those on the bench.
Angola started with star winger Hermenegildo Geraldo after bringing him on as a second-half substitute in draws against Tunisia and Mauritania.
The countries were involved in the greatest Cup of Nations comeback with Mali wiping out a four-goal deficit on 77 minutes to draw 4-4 with 2010 hosts Angola in Luanda.
There was only one goal during the first half in Ismailia with Haidara putting the Malian Eagles ahead on 37 minutes.
After a patient build-up just outside the Angolan box, Haidara unleashed an unstoppable shot that flew wide of goalkeeper Tony Cabaca and into the corner of the net.
Mali should have been more than one goal ahead by half-time as unmarked Kalifa Coulibaly headed wide from close range.
Strangely lethargic during the opening half, Angola were more assertive after half-time and troubled the Mali defence regularly without making the crucial breakthrough.
After suffering a 4-1 hiding from Mali in their opening match, Mauritania kept a second successive clean sheet to contain Tunisia and bow out with heads held high.
Tunisia have been a major disappointment so far under French coach Alain Giresse, failing to win any of three group matches.
Africa Cup of Nations last-16 draw after completion of group stage on Tuesday (all kick-off times SA time):
Friday, July 5
Morocco v Benin, Al Salam Stadium, Cairo - 18:00
Uganda v Senegal, Cairo International Stadium - 21:00
Saturday, July 6
Nigeria v Cameroon, Alexandria Stadium - 18:00
Egypt v South Africa, Cairo International Stadium - 21:00
Sunday, July 7
Madagascar v Democratic Republic of Congo, Alexandria Stadium - 18:00
Algeria v Guinea, 30 June Stadium, Cairo - 21:00
Monday, July 8
Mali v Ivory Coast, Suez Stadium - 18:00
Ghana v Tunisia, Ismailia Stadium - 21:00
Wednesday, July 10
Uganda/Senegal v Morocco/Benin, 30 June Stadium - 18:00
Cameroon/Nigeria v Egypt/South Africa, Cairo International Stadium - 21:00
Thursday, July 11
Mali/Ivory Coast v Algeria/Guinea, Suez Stadium - 18:00
Madagascar/DR Congo v Ghana/Tunisia, Al Salam Stadium - 21:00
Sunday, July 14
Uganda/Senegal/Morocco/Benin v Madagascar/DR Congo/Ghana/Tunisia, 30 June Stadium - 18:00
Mali/Ivory Coast/Algeria/Guinea v Cameroon/Nigeria/Egypt/South Africa, Cairo International Stadium - 21:00
Wednesday, July 17
Losing semi-finalists, Al Salam Stadium - 21:00
Friday, July 19
Winning semi-finalists, Cairo International Stadium - 21:00