Brazil beat Spain in a penalty shootout Sunday in a quarterfinal game viewed as the ''real final'' between the two best teams in the Under-20 World Cup

In the end it came down to chance with Brazil winning 4-2 on penalties after a 1-1 draw through 90 minutes and a 2-2 stalemate after 30 minutes of extra time.

In the other quarterfinal Sunday, France edged Nigeria 3-2 in extra time.

In the semifinals Wednesday, Brazil will face Mexico, and France will play Portugal.

The final is Saturday in Bogota.

Brazil has won the title four times and Portugal twice. Mexico and France will be trying to break through for their first.

Spain coach Julen Lopetegui made it clear he thought the better team lost. Spain led in possession, outshot Brazil 26-17 and led in corners 12-5.

''I feel very proud of these kids,'' Lopetegui said. ''I think overall they were better than Brazil and deserved to advance. Today, the best team in the World Cup is out.''

In truth, there was nothing to choose from.

The two best teams in the field thrilled the crowd with end-to-end soccer, possession passing and counterattacking to keep the other side off balance. Spain came back twice, and Brazil was rock solid to pull through on penalties.

''As we anticipated, it was a very difficult match against a very top team - strong and excellent,'' Brazil coach Ney Franco said. ''We had great penalty takers and a keeper who made the difference.''

Willian gave Brazil the lead in the 35th, before Rodrigo - who was born in Brazil - equalized for Spain in the 57th. Brazil went ahead with Dudu's goal in extra time, but Spain answered two minutes later thanks to Alvaro Vazquez.

Vazquez is the tournament's leading goal scorer with five.

First to take its kick, Spain fell behind when its first penalty-taker, Jordi Amat, was stopped by a diving Brazil keeper Gabriel. Vazquez also missed Spain's fourth penalty when Gabriel kicked the shot away.

In the meantime, Brazil converted its four from Casemiro, Henrique, Danilo and Dudu.

Mexico is on a roll and will have lots of motivation against Brazil. Mexico's senior team won the regional Gold Cup title in June, defeating the United States 4-2, and added the Under-17 World Cup title in July, beating Uruguay 2-0 in the final at Aztec stadium in Mexico City.

Were it not for the drama of Brazil vs. Spain, France's 3-2 win over Nigeria in extra time would grab more headlines. Nigeria won its first four matches and was seen by many as a match for Brazil or Spain.

France changed that.

Gueida Fofana gave France a 2-1 lead in the 102nd minute. Two minutes later, Alexandre Lacazette scored his second goal of the match to seal the victory. Maduabuchi Ejike scored his second goal in the 111th to give Nigeria hope of a comeback, but the west Africans couldn't score again.

France should have won in regulation, but Nigeria equalized in the final seconds of second-half stoppage time on a header by Ejike. Lacazette gave France the lead in the 50th with his first goal of the match.

This is the first time France has reached the semifinals of the Under-20 World Cup.

''This is the achievement of a new generation,'' France coach Francis Smerecki said. ''This showed when Nigeria tied the match. I think we can end up as champions, but we are aware there are some strong rivals.''

Nigeria came into the match having won its first four decisions and was the highest scoring team in the tournament. But France managed to slow the Nigerian attack for most of the game, giving up possession but few threatening chances.

The elimination is another disappointment for the Nigerians, who have finished second two times - in 1989 and 2005.

''It is sad to go out like this,'' Nigeria coach John Obuh said. ''We believe this is a game we should have won.''