The marquee matchup of the second round more than lived up to the hype.

Spain rallied from a two-goal deficit to stun Brazil 4-2 in extra time at the FIFA U-20 World Cup soccer tournament Wednesday night in Burnaby, B.C.

Spain's Diego Capel, right, reacts after getting tangled up with Brazilian Marcelo while trying to get around for a shot in FIFA U-20 action Wednesday night in Burnaby, B.C.Spain's Diego Capel, right, reacts after getting tangled up with Brazilian Marcelo while trying to get around for a shot in FIFA U-20 action Wednesday night in Burnaby, B.C.
(Richard Lam/Canadian Press)

Alberto Bueno's goal in the 12th minute of extra time eliminated the four-time champion Brazilians, one of the favourites heading into the tournament.

With Spain on the attack, forward Diego Capel sent a crossing pass to Bueno, who headed the ball by Brazil's goalkeeper, Cassio.

Adrian Lopez added a fourth goal in the final minute to end any hope of a comeback by Brazil.

"The reaction of the team after the score was 2-0 was very, very important," said Esteban Granero, a second-half substitute who was involved in the play that led to Bueno's goal.

"Our physical condition enabled us to attack more in the extra time."

Gerard Pique and Javi Garcia scored for Spain in regulation time, setting up the heroics by Bueno.

Forwards Leandro Lima and Pato replied for Brazil.

Spain advances to the quarter-finals to play the Czech Republic on Saturday night (CBC, 7:30 p.m. ET) at Commonwealth Stadium in Edmonton. The Czechs defeated Japan 4-3 on penalty kicks Wednesday.

"We have to be a team all the time and we have been a team tonight," Granero said.

"It is more important to win and have difficulty. Today we have been more a team than ever."

Brazil and Spain thrilled the B.C. crowd with skill and precision passing.

The contest was a rematch of the 2003 final in the United Arab Emirates, when Brazil emerged victorious.

After garnering few chances in the opening part of the match, the two teams combined for three goals in the final six minutes of the first half.

Lima used superb agility to score Brazil's first goal in the 39th minute. Lima controlled the ball with his chest in the penalty area, then fired a shot while in the air past Spanish goalkeeper Adan.

Brazil stunned Spain with its second goal two minutes later on Pato's third marker of the tournament. Marcelo made a nifty move on Spanish defender Sunny Stephen, sent a crossing pass to Pato, who headed the ball by Adan.

"We had the game in hand at 2-0," said Pato. "After Spain scored the second goal, the team was feeling really down and we could not recover."

Spain's first goal protested by Brazil

The Spaniards replied with a questionable goal in the 43rd minute, when Pique redirected a free kick by keeper Cassio, reducing Brazil's lead to 2-1.

While replays showed the ball went off the arm of Pique, Swedish referee Martin Hansson allowed the goal to stand despite protests from the Brazilian side.

Spanish coach Gines Melendez said the teams didn't get down after the early deficit. 

"We dominated the match, I think, and after this result of 2-0 … it is very difficult for a team to play their best and we have gone through this," he said through an interpreter.

"I have to point out that in the last 20 minutes of the match we had six opportunities to score another goal."

Adan prevented Brazil from going up by two goals in the 55th minute, quickly moving to his left to stop shot inside the box.

The Spanish goalkeeper remained strong in the second half, robbing forward Luiz Adriano off a perfectly placed header from a crossing pass.

Adan's brilliant play allowed Spain to get the equalizer late in the second half, forcing 30 minutes of extra time.

Midfielder Garcia surprised Cassio with a quick shot on a free kick in the 84th minute. Brazil looked confused on the play, failing to set up a defensive wall before Garcia's shot.

The momentum of the goal clearly lifted Spain, who continually blew past exhausted Brazilian defenders to create numerous scoring chances in extra time.