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.
Vincent Aboubakar header the winner in stoppage time but his joy immediately turned to disappointment as he was given a second yellow card for taking his shirt off.
Cameroon had acquitted themselves well throughout as Bryan Mbuemo brought an outstanding save from Manchester City's Ederson, deputising for Liverpool keeper Alisson, but Switzerland's victory over Serbia ended the African team's chances of reaching the last 16.
With his side having already qualified after their first two games, Brazil coach Tite made 10 changes and Arsenal's Gabriel Martinelli took the chance to impress with a fine performance in which he was thwarted on several occasions by Cameroon keeper Devis Epassy.
The pre-tournament favourites finished top of Group G despite the loss and now meet South Korea in the knockout phase after their dramatic late win against Portugal saw them edge out Uruguay, who beat Ghana, on goals scored.
Brazil on cruise control
Brazil were in the comfort zone after winning their group games against Serbia and Switzerland, affording coach Tite the opportunity to shuffle his powerful squad while demonstrating the range of resources at his disposal.
They may have lost this game, but with qualification assured Tite may not be too disappointed at the defeat as it did not inflict any damage on their group standing, and he now has fresh legs for when the knockout stage starts.
Arsenal's 21-year-old Martinelli was Brazil's outstanding performer, with Cameroon keeper Epassy producing fine stops from an early header, and a shot destined for the top corner in the second half.
Martinelli's tireless running combined with quality proved a thorn in Cameroon's side and made an eloquent case for his inclusion should Tite wish to make changes as the World Cup progresses.
Brazil have shown enough in their two victories to justify the pre-tournament optimism surrounding their chances - now they will hope Neymar, who acclaimed the fans with his team-mates on the pitch after the final whistle, can recover from the ankle injury sustained against Serbia in time to make his expected contribution.
Cameroon bow out in style
Cameroon may be out of the World Cup but Rigobert Song's side certainly added to the quality and excitement that has marked the group stages here in Qatar.
Brazil had most of the chances at Lusail Stadium but Cameroon were always in the game and posed a threat, which came to fruition when the extrovert Aboubakar directed his header past Ederson during nine minutes of stoppage time.
He paid the price for ripping his shirt off in celebration as referee Ismail Elfath almost apologetically pulled out a second yellow card, followed by the red.
Goalkeeper Epassy also distinguished himself, particularly at the expense of Martinelli, to earn the award as man of the match.
Cameroon were ultimately undone by their opening-game defeat against Switzerland but showed character and quality to fight back from 3-1 down to earn a 3-3 draw against Serbia, and then beat mighty Brazil in front of 85,986 fans here in Lusail.
"The Indomitable Lions" may be going home but they have certainly had their moments in Qatar.
Player of the match
AboubakarVincent Aboubakar
Cameroon
Squad number10Player nameAboubakar
Squad number20Player nameMbeumo
Squad number22Player nameNtcham
Squad number2Player nameNgom Mbekeli
Squad number13Player nameChoupo-Moting
Squad number12Player nameToko-Ekambi
Squad number8Player nameAnguissa
Squad number6Player nameNgamaleu
Squad number15Player nameKunde
Squad number25Player nameTolo
Squad number4Player nameWooh
Squad number19Player nameCollins Fai
Squad number24Player nameEbosse
Squad number16Player nameEpassy
Line-ups
Cameroon
Formation 4-2-3-1
16Epassy
19Fai Collins4Wooh24Ebosse25Tolo
15Kunde8Anguissa
20Mbeumo13Choupo-Moting6Ngamaleu
10Aboubakar
16Epassy19Fai CollinsBooked at 32mins4Wooh24Ebosse25ToloBooked at 6mins15KundeBooked at 28minsSubstituted forNtchamat 68'minutes8Anguissa20MbeumoSubstituted forToko-Ekambiat 64'minutes13Choupo-Moting6NgamaleuSubstituted forNgom Mbekeliat 86'minutes10AboubakarBooked at 90minsSubstitutes
1Ngapandouetnbu2Ngom Mbekeli5Ondoua7Nkoudou9Nsame11Bassogog12Toko-Ekambi14Oum Gouet17Mbaizo22Ntcham26MarouBrazil
Formation 4-2-3-1
23Ederson
13Alves da Silva14Militão24Bremer16Alex Telles
8Fred15Fabinho
19Antony21Rodrygo26Martinelli
18Gabriel Jesus
23Ederson13Alves da Silva14MilitãoBooked at 7mins24Bremer16Alex TellesSubstituted forMarquinhosat 54'minutes8FredSubstituted forBruno Guimarãesat 55'minutesBooked at 85mins15Fabinho19AntonySubstituted forRaphinhaat 79'minutes21RodrygoSubstituted forÉverton Ribeiroat 55'minutes26Martinelli18Gabriel JesusSubstituted forPedroat 64'minutesSubstitutes
1Alisson3Thiago Silva4Marquinhos5Casemiro7Lucas Paquetá9Richarlison11Raphinha12Weverton17Bruno Guimarães20Vinícius Júnior22Éverton Ribeiro25PedroReferee:Ismail ElfathAttendance:85,986Live Text
Match ends, Cameroon 1, Brazil 0.
Second Half ends, Cameroon 1, Brazil 0.
Attempt missed. Bruno Guimarães (Brazil) right footed shot from very close range is too high. Assisted by Marquinhos.
Attempt missed. Gabriel Martinelli (Brazil) header from very close range is close, but misses to the right. Assisted by Marquinhos with a headed pass.
Attempt saved. Bruno Guimarães (Brazil) header from the centre of the box is saved in the top left corner. Assisted by Marquinhos with a cross.
Attempt missed. Pedro (Brazil) header from the centre of the box is close, but misses to the right. Assisted by Gabriel Martinelli with a cross.
Second yellow card to Vincent Aboubakar (Cameroon) for excessive celebration.
Goal! Cameroon 1, Brazil 0. Vincent Aboubakar (Cameroon) header from the centre of the box to the bottom right corner. Assisted by Jerome Ngom Mbekeli with a cross.
Corner, Brazil. Conceded by Christopher Wooh.
Attempt missed. Pedro (Brazil) left footed shot from the centre of the box is high and wide to the left. Assisted by Raphinha.
Substitution, Cameroon. Jerome Ngom Mbekeli replaces Moumi Ngamaleu.
Bruno Guimarães (Brazil) is shown the yellow card for a bad foul.
Foul by Bruno Guimarães (Brazil).
Moumi Ngamaleu (Cameroon) wins a free kick in the defensive half.
Corner, Brazil. Conceded by Christopher Wooh.
Attempt blocked. Bruno Guimarães (Brazil) right footed shot from the right side of the six yard box is blocked. Assisted by Raphinha with a cross.
Vincent Aboubakar (Cameroon) is shown the yellow card for a bad foul.
Gabriel Martinelli (Brazil) wins a free kick on the right wing.
Foul by Vincent Aboubakar (Cameroon).
Attempt missed. Christopher Wooh (Cameroon) right footed shot from the centre of the box is high and wide to the right. Assisted by Karl Toko-Ekambi with a cross following a corner.
Get the latest results and goal notifications for any team at the Fifa World Cup by downloading the BBC Sport app: Appleexternal-link - Androidexternal-link - Amazonexternal-link
Get your daily dose of Fifa World Cup reaction, debate & analysis with World Cup Daily on BBC Sounds