The Indomitable Lions of Cameroon defeated a Brazil side resting a host of regulars but still saw their World Cup campaign ended after an entertaining encounter at Lusail Stadium.
It was Vincent Aboubakar who headed the winner in stoppage time but he was given a second yellow card for taking his shirt off.
Brazil have already qualified, so coach Tite rested 10 players.
But, Cameroon fail to qualify as Switzerland defeated Serbia to join Brazil in the knockout stage. Cameroon, thus, become the first African side to defeat Brazil at the World Cup.
Brazil will lurk horns with South Korea while Portugal will take on Switzerland in the round of 16.