The Confederations Cup has got the final that nearly everyone wanted.

The World Cup holder against the five-time champion. The two-time European champions against the tournament host. Spain's passing wizards vs. Brazil's new star Neymar .

Spain came through an exhausting encounter by winning a penalty shootout 7-6 over Italy in the semifinal on Thursday and will face Brazil in Rio de Janeiro's Maracana Stadium on Sunday to cap the World Cup warmup tournament.

''I think everybody was waiting for this Confederations Cup final to be Spain vs. Brazil,'' Spain captain Iker Casillas said. ''I think the two teams that deserve to play the final are actually playing it.''

Jesus Navas scored the decisive penalty in the shootout after extra time ended 0-0 in a draining match that was made more difficult by heat and thick humidity.

Nobody missed in the shootout until Italy defender Leonardo Bonucci shot over the bar to give Navas an attempt at the winner. The recently signed Manchester City midfielder cooly beat goalkeeper Gianluigi Buffon to end a top-class battle and send Spain to another major final.

While calling his squad ''lucky'' to win , Spain coach Vicente del Bosque was not about to concede the final due to fatigue, even though Spain has one less day of rest than Brazil, which beat Uruguay 2-1 Wednesday.

''We have to now consider what we have to do in the three days to recover. And we will definitely stand up to Brazil in the Maracana,'' the manager said. ''The players should feel just as happy as kids playing in the Maracana. They have won a lot, but they want to win in the Maracana.

It will be the fourth major final Spain will play in five years, while Brazil is hoping to rekindle its glory under Felipe Scolari, who led the Selecao to the 2002 World Cup title.

''It will be a special match for the Brazilians, and also for the Spanish team to play in the Maracana,'' Casillas said. ''This is something very enticing and it whets our appetite.''

Against Italy, Spain was pushed to the limit in an intense match from start to finish that saw each side hit the woodwork in extra time. Emanuele Giaccherini smashed a shot off the post in the 93rd minute and Buffon deflected a shot from Xavi Hernandez off the post in the 115th.

In a rematch of the Euro 2012 final, which Spain won 4-0, Italy threatened early on even without the injured Mario Balotelli, relying on counterattacks, while Spain relied on its usual game of short passing and ball possession.

''We played a great match. We created and we conceded but we were always in the match,'' Italy coach Cesare Prandelli said. ''They're still ahead of us but we're improving.''

Before kickoff, about 5,000 anti-government protesters battled police about 2 kilometers (1 mile) from the stadium.

More protests are expected at Sunday's final of the World Cup warm-up tournament.

Thursdays' were the latest in a series of massive, nationwide protests that have hit Brazil since June 17. Demonstrators are angered about corruption and poor public services despite a heavy tax burden.

Protests are also denouncing the billions of dollars spent to host the World Cup and the 2016 Olympics in Rio de Janeiro.

Sunday is the fourth major final Spain will play in five years, having won the 2008 and 2012 European Championships plus the 2010 World Cup.

Inside the Fortaleza stadium, which appeared full, there was overwhelming support for Italy from local fans, who were perhaps afraid of facing Spain in the final. Spain was booed early on every time it took the ball.

Christian Maggio had the best chance of the first half in the 36th with a header inside the box that Spain goalkeeper Iker Casillas did well to block.

A minute later, Xavi Hernandez set up Spain's only real chance early on but Fernando Torres shot wide.

Reverting to a three-man defense, Prandelli made another tactical move to start the second half, replacing center back Andrea Barzagli with midfielder Riccardo Montolivo and putting De Rossi at the center of the defense.

Seeking to inject some energy into his squad, Spain coach Vicente Del Bosque sent on Navas for David Silva in the 52nd and Navas had the first significant chance of the second half six minutes later with a long, low effort that Buffon controlled.

The roles reversed as the second half wore on, with Italy controlling more and Spain resorting more to counterattacks. Italy had a series of corner kicks at one point but had trouble producing chances.

Navas threatened in the 92nd with a long shot that appeared to surprise Buffon but the goalkeeper quickly recovered. A minute later, Giaccherini hit the post and then Jordi Alba volleyed high from close range as all of a sudden there was a flurry of chances.

In the shootout, Italy went first and Antonio Candreva, Alberto Aquilani, Daniele De Rossi, Sebastian Giovinco, Andrea Pirlo and Montolivo each converted near perfect penalties for the Azzurri.

However, Bonucci is a center back who rarely, if ever, takes penalties, and his attempt was far over the bar.

Spain matched Italy shot for shot with Xavi, Andres Iniesta, Gerard Pique, Sergio Ramos, Juan Mata and Sergio Busquets each finding the target before Navas stepped up.

Buffon guessed right on Navas' shot but the ball was so close to the striker's left post that the goalkeeper had no chance.