Goals by Paulinho and Thiago Silva steered a much-improved Brazil to a 2-0 victory over a battling but ultimately outclassed Serbia and into a FIFA World Cup second-round meeting with Mexico.
The win, combined with Switzerland's 2-2 draw with Costa Rica, meant Brazil finished top of Group E on seven points, two ahead of the Swiss, who will face Sweden in the last 16. Serbia ended in third place on three points and are eliminated along with Costa Rica.
With defending champions Germany knocked out and Argentina scraping through at the death, five-times champions Brazil were desperate to stamp their authority on a tournament where World Cup pedigree has counted for so little.
Read more of our FIFA 2018 coverage:
But, having needed two goals in stoppage-time to beat Costa Rica in their last game having been held 1-1 by Switzerland in their opener, they took a long time to make any impression on a well-drilled and rugged Serbian defence.
Switzerland kept politics off the field and Costa Rica broke their World Cup duck in a thrilling 2-2 draw that saw the Europeans through to the next round of the World Cup where they will face Sweden.
Pre-match attention had focussed on Granit Xhaka and Xherdan Shaqiri's politicised "eagle" celebrations in their last game, and Costa Rica being the only team without a tournament goal.
But this time, the Swiss kept their focus purely on their game and took a 31st minute lead when forward Blerim Dzemaili blasted past Costa Rica goalkeeper Keylor Navas from close range following a nod down from Breel Embolo.
Already-eliminated Costa Rica twice hit the woodwork in a frustrating opening 15 minutes of missed chances at the Nizhny Novgorod Stadium on the banks of the river Volga.
But the Central Americans finally scored their first goal in Russia when defender Kendall Waston powered home Joel Campbell's corner in the 56th minute, triggering mass celebrations like they had won the trophy.
Swiss substitute Josip Drmic drilled home his team's second in the 88th minute, before Bryan Ruiz struck a stoppage time penalty that hit the crossbar and went in off goalkeeper Yann Sommer's back.
There was a sour note for the Swiss, however, when captain Stephan Lichtsteiner, who supplied the cross for their first goal, took a second yellow card, meaning he will miss the knockout clash with Sweden.
Despite their joy at scoring, Costa Rica's tournament has overall been a disappointment for their legions of red-clad fans and a far cry from their glorious 2014 run to the quarter-finals when they lost on a penalty shootout.
Switzerland, driven on by the inventive Shaqiri, ended Group E as runners-up to Brazil, who beat Serbia 2-0 to top the group.
Both sides could have won a free-flowing and open-ended game in Nizhny Novgorod, with a flurry of late chances.