Two excellent goals from defender Jordi Alba, one of eight Barcelona players in the starting lineup, and a fifth of the tournament from Fernando Torres gave Spain a third successive win and top spot in Group B.
They stretched their unbeaten run in competitive games to 28, going back to their 1-0 defeat to Switzerland at the 2010 World Cup, and have not lost at all since England beat them in a friendly in November 2011.
They will face Italy, who they beat 4-0 to win the European title in Kiev a year ago, at Fortaleza's Castelao in Thursday's semi-final.
A young and largely experimental Nigeria team, after beating Tahiti 6-1, finished third after defeats to Uruguay and Spain and must now concentrate of qualifying for the World Cup.
They need a draw against Malawi in September to top their African qualifying group and will then have to play off over two legs with another group winner to earn a return trip to Brazil next year.
Although Spain did not have it all their own way, Spain coach Vicente del Bosque was pleased.
"Nigeria were very dangerous in the first half and they played with plenty of dynamism and made it difficult for us," he told reporters.
"When it is as hot as it was today you cannot play like that for 90 minutes and Nigeria had to slow down.
"They were a bit less intense in the second half and we played better."
Nigeria coach Stephen Keshi was upset at the way his team lost their discipline after Torres, who had only replaced Roberto Soldado three minutes previously, scored with a diving header to make it 2-0 in the 62nd minute.
"We wasted a lot of chances. The players showed too much anxiety in front of goal. The good thing is we are creating a lot of chances, but we are not taking them. That is something we have to work on and hopefully it will come quickly.
"But we showed a lack of professionalism after we went 2-0 down and I was not happy about that, we lost our discipline."
Alba slalomed his way past four opponents and got a lucky deflection off the shin of defender Kenneth Omeruo before firing home from eight metres for a wonderful goal in the third minute.
The 19-year-old Omeruo, the youngest member of the Nigerian squad, had even worse luck eight minutes later when he was injured and carried off on a stretcher.
Chances regularly fell to both sides in an exciting end-to-end game with John Obi Mikel, Joseph Akpala and Brown Ideye all going close for Nigeria, who played without fear and pounded forwards.
Soldado had two good chances to increase Spain's advantage before the break but was twice thwarted by Nigeria keeper Vincent Enyeama.
Cesc Fabregas held his head in disbelief when he strode on to a cross from Soldado but, with only Enyeama to beat, shot against the post with the rebound flying straight into the goalkeeper's grasp.
It was a different story after half-time with Spain midfielders Andres Iniesta and Xavi t
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.