Cameroon defeated a second-string Brazil team 1-0 in their final Group G match at the Lusail Stadium, but it was not enough as the African side were knocked out of the competition.
Cameroon finished third on four points, two points below second-placed Switzerland, who defeated Serbia 3-2. Brazil, who had already qualified, finished on top on goal difference with six points and will face South Korea in the last 16.
Fred, Antony and Bruno Guimaraes all came close to scoring, while Gabriel Martinelli was the stand-out player for the five-time champions, who looked set for a goalless draw.
But Cameroon finally broke the deadlock when captain Vincent Aboubakar powered in a header in the third minute of stoppage time before being sent off for collecting a second yellow card for taking off his shirt in the celebration.
Elsewhere, Switzerland powered past Serbia to advance to the last 16 for the third straight time.
The win sealed second spot in the group with six points, level with Brazil, and the Swiss will next face Portugal for a place in the quarter-finals.
Switzerland took the lead through Xherdan Shaqiri's deflected shot in the 20th minute, making the winger nicknamed 'the pocket rocket' the first player from his country to score at three World Cups.
Their joy only lasted six minutes with Serbia, needing a win to have any chance of progressing, scoring twice through Aleksandar Mitrovic and Dusan Vlahovic to turn the game around.
But Switzerland responded with a two goals either side of the break from Breel Embolo and Remo Freuler to prolong their stay in Qatar while eliminating the Serbs.
Reuters