Brazil won a heated matchup of past and present soccer powers, boosting its confidence as it prepares to host next year's World Cup.
Fred scored two goals, Neymar added another and Brazil defeated world champion Spain 3-0 in the Confederations Cup final on Sunday night as protesters clashed with riot police outside Maracana Stadium.
Brazil, a five-time world champion, beat the reigning world and European champion and ended Spain's 29-game, three-year winning streak in competitive matches.
"We beat the world champions today, but we know that the tournament that we will be playing next year will be a lot more difficult," Brazil coach Luiz Felipe Scolari said. "Now we have more confidence. That's what we needed."
Brazil ahead in the second minute, Neymar doubled the lead in the 44th with his fourth goal of the tournament and Fred added his fifth in the 47th.
Brazil, which won its third straight Confederations Cup, has not lost a competitive home match since 1975.
Spain, which had not lost a competitive game since its 2010 World Cup opener against Switzerland, had a miserable night. Sergio Ramos sent a penalty kick wide in the 55th and defender Gerard Pique was ejected by Dutch referee Bjorn Kuipers with a straight red card for fouling Neymar in the 68th.
"They were superior on every way," Spain coach Vicente Del Bosque said. "They scored early. This is not an excuse but they had pressure on us all the time."
Eliminated in the quarterfinals of the last two World Cups, the Selecao entered the tournament having not played a competitive match since the 2011 Copa America, Brazil had slipped to 22nd in the FIFA rankings, between Ghana and Mali.
Spain, ranked first for the past 20 months, is the most accomplished national team of the 21st century, winning its first World Cup in 2010 between titles in the 2008 and 2012 European Championships.
But in the stadium that will host the World Cup final on July 14 next year, Brazil dominated La Furia Roja.
"The champion is back," chanted the crowd of more than 73,000 people at the renovated Maracana.
It also didn't take long before the fans — in a sea of yellow jerseys — started teasing the Spaniards, chanting "Wanna play, wanna play!? Brazil will teach you."
Spain had been unbeaten in 26 matches overall, including friendlies, since a 1-0 loss to England in London in 2011 and had outscored opponents 69-11 in competitive matches since the loss to Switzerland in South Africa.
But Spain had not played Brazil since a 1999 exhibition, and they hadn't met in a competitive match since the Selecao's 1-0 win in the first round of the 1986 World Cup in Mexico.