Senegal, the 2021 champions, survived captain Kalidou Koulibaly's sending off on his 100th appearance for the team by routing Benin 3-0 in Group D in Tangier on Tuesday.
Congo finished second in the group on goal difference with a 3-0 win over already eliminated Botswana in Rabat.
Senegal, Congo and Benin were already assured of their places in the last 16.
But Tanzania and Tunisia were not. They progressed from Group C by playing out a 1-1 draw that eliminated Angola.
Feisal Salum's goal for Tanzania, which cancelled out Ismaël Gharbi's penalty, sent the Taifa Stars to the last 16 as one of the six groups' best third-place finishers.
Angola, who finished third in Group B, had been hoping for a favour from Tunisia to beat Tanzania and another from Nigeria, which complied by defeating Uganda 3-1.
But Tanzania's goal proved the difference. Both Tanzania and Angola finished with two points and a goal difference of minus 1. Salum's goal meant the Taifa Stars had scored more in the group stage (Tanzania's three goals vs. Angola's two), meaning they go through to the next round.
Tunisia advance as Group C runner-up, but it wasn't enough to appease their fans, who whistled the team after supporting them in the rain in Rabat.
With his team already assured of top spot, Nigeria coach Eric Chelle opted to rest many of his regulars including Ademola Lookman, Alex Iwobi and Bright Osayi-Samuel. Victor Osimhen played from the start.
Fisayo Dele-Bashiru crossed for Paul Onuachu to score with a simple finish in the 28th, and Uganda's slim hopes were effectively ended early in the second half. Goalkeeper Denis Onyango was unable to resume after the break, and his replacement Salim Magoola was sent off in the 50th for handling the ball outside the penalty area. Magoola couldn't resist stopping a shot from Osimhen.
Uganda's third-choice goalkeeper Nafian Alionzi soon conceded when Raphael Onyedika shot the ball between his legs for 2-0 in the 62nd, five minutes before Onyedika got another goal.
Rogers Mato restored some Ugandan pride in the 75th with a fine chip over Francis Uzoho in the Nigeria goal.
Senegal's big win over Benin ensured they will stay in Tangier for their first knockout game on Saturday against a third-place finisher from Groups B, E or F.
But the 2021 champions will be without the suspended Koulibaly.
Nigeria will stay in Fez for a game against a third-place finisher on January 5.
Congo next face Algeria in Rabat on January 6. The Leopards can get a good look at their opponents on Wednesday, when Algeria play Equatorial Guinea in their final group game.
Tunisia will play Mali in Casablanca on Saturday.
Benin and the other third-place finishers will face matches against group winners.