Riot police fired tear gas as demonstrators threw missiles near the Maracana football stadium.
President Dilma Rousseff did not attend the match. She was booed at the opening of the tournament.
The protests started nearly a month ago, sparked by transport fare rises, but quickly encompassed other issues.
The main grievances are over the costs of staging the World Cup, corruption and demands for better health, education and transport.
Earlier on Sunday a group of demonstrators tried to storm a Brazilian Football Association (CBF) building in Rio. But police kept them back and the group settled outside the building.
The protesters demanded the resignation of CBF president Jose Maria Marin, who has been accused of incompetence.
In a separate protest, several thousand people marched on Maracana stadium banging drums.
They demanded free public transport, carrying placards reading “FIFA – you pay the bill”. The demonstrators also called for and end to corruption and the resignation of the Rio State governor.
Minutes before the game began, small groups of protesters threw rocks and firecrackers at police lines.
Security forces responded with tear gas and sent armored vehicles to disperse the demonstrators. There were no further incidents during the game – which saw Brazil beat Spain 3-0.
The wave of protests began nearly a month ago in the city Sao Paulo after bus fares were increased by 10%.
But after heavy-handed police action, it spread to other cities and mobilized public opinion.
The rises in Sao Paulo and many other Brazilian cities were revoked after two weeks of protests.
By then, the demonstrations had turned into a nationwide movement for better education, healthcare and transport.
IMrj55uvz6IImage source: Wikimedia Commons President-elect Donald Trump celebrated his election victory at the Ultimate Fighting…
Millions of voters across the US chose to return Donald Trump to the White House…
Donald Trump declares victory in the US election as he addresses jubilant supporters in Florida.…
Stocks around the world are rising as Donald Trump appears to be on the cusp…
Donald Trump has won Pennsylvania, North Carolina and Georgia and taken a lead over Kamala…
Quincy Jones, the celebrated musician and producer who worked with Michael Jackson, Frank Sinatra, Ray…