Spain will face Italy in the Confederations Cup semi-finals after they beat Nigeria to top Group B.
Jordi Alba scored twice, stroking in following a flowing move early on and then rounding Nigerian goalkeeper Vincent Enyeama with two minutes left.
Nigeria caused problems for Spain's defence in between with John Mikel Obi and Sunday Mba going close.
Fernando Torres headed in two minutes after coming on as a substitute, before Alba sealed it to knock Nigeria out.
The goal from Chelsea striker Torres took the heat out of the contest, but despite Spain's superiority in possession, Nigeria were let down again by poor finishing when substitute Gambo Muhammad squirmed the ball wide with 15 minutes left.
He was set up by the impressive Ahmed Musa, who also created a great opportunity for Brown Ideye, but the striker's touch let him down in front of an open goal.
And although coach Stephen Keshi's Super Eagles bow out of the tournament with a solitary victory over Tahiti to finish third in Group B behind Uruguay, there were signs of encouragement for his young side.
Had they converted their chances the story of this game might have been different, but there was a sense that Spain still had another gear to move into if they needed it.
The world champions established early control from the kick-off with Andres Iniesta testing Enyeama before he played his part in Alba's breakthrough goal after three minutes.
As the ball was shifted to right to left in Spain's midfield, Iniesta latched onto it and played in the on-rushing Alba, who was perhaps fortunate to receive the ball back off Kenneth Omeruo before calmly passing the ball into the net.
Despite an overwhelming advantage after beating Uruguay in their first game and hitting 10 goals past Tahiti, Spain still needed at least a point coming into this game to confirm their semi-final place in a competition they are yet to win.
So it was perhaps no surprise that boss Vicente Del Bosque re-introduced his first team, with only Sergio Ramos remaining from the Tahiti mauling and Victor Valdes named in goal.
But with Nigeria still having an outside chance of qualifying, they committed to attack too, and only a Ramos block to deny Mikel and Valdes's save from Mba's shot prevented the Super Eagles from equalising.
Last time these two sides met, Nigeria beat Spain in the group stages of the 1998 World Cup, and at times Keshi's team caused further concern for Spain.
La Roja created the better opportunities before the break, though. Roberto Soldado should really have taken one of two chances when he was put through on goal. On both occasions, Enyeama produced good saves. Soldado then crossed for Barcelona's Cesc Fabregas, who hit the post.
Nigeria responded once more just after the interval when the pace of Musa allowed him to whip in a superb cross for Ideye, but the striker's touch was clumsy.
Two minutes after coming on as a substitute, Torres then showed Ideye how it should be done by heading in Pedro's centre following a smart move.
It took his total for the tournament to five goals overall and killed the game as a contest although Muhammad could have created a more exciting finish had he shown greater composure.
Alba had the final say by controlling David Villa's long free-kick, beating Enyeama and booking Spain's spot in the last four with a 100% record.
Spain coach Vicente Del Bosque:
"It was a difficult match. We had an excellent rival who fought for the ball. In the end we were able to control the ball and break the match.
"[Italy] is a challenge for us. We want to play the final.
"For Italy it'll also be a very important match, because after the final of the European Championship, I guess they'll want revenge."
Nigeria coach Stephen Keshi:
"We played against a better side, a team who've been together for a long time.
"It's a learning process for us, it's good. We have to continue from where we stopped here and build on that."