Vicente Del Bosque's side dominated on the ball as usual but was frustrated for long periods by Portugal, which had decent chances of its own at Cape Town's Green Point Stadium.
Ultimately Spain's patience paid off, however, as David Villa's 63rd-minute goal secured victory exactly two years to the day since its European triumph in Austria.
Spain will now fancy itself in a quarter-final clash with modest South American team Paraguay while Portugal - which had Ricardo Costa dismissed in the final minute - faces a disappointing trip home.
Fernando Torres, without a goal in South Africa, tested Portugal goalkeeper Eduardo after just a minute and strike partner Villa also forced an early save.
The lively start continued when Villa, coming in from the left again, fired in a low effort which Eduardo stopped smartly.
Another Torres shot from a short corner was not too far over the bar but for all Spain's dominance, he and Villa were largely restricted to playing out wide.
Portugal had perhaps the best chance so far in the 20th minute. Midfielder Tiago tried his luck from the edge of the box and after Iker Casillas could only push it high into the air, he had to scramble it away near his own goal-line.
Xavi and Villa tried their luck at the other end before Spain teammate Xabi Alonso saw a couple of long-range attempts stifled.
Portugal had a clear chance in the 39th minute when Almeida was unable to properly connect with Raul Meireles' cross, to the disappointment of a better-placed Cristiano Ronaldo behind him.
Casillas raced out to halt Simao's run at goal before Tiago headed over a good chance.
Seven minutes into the second half Spain defender Gerard Pique was outpaced by Almeida down the left and when the Werder Bremen striker's attempted centre deflected off Carles Puyol's thigh, the defender was relieved to see the ball go narrowly wide.
Portugal boss Carlos Queiroz sent Danny on for Almeida while Vicente Del Bosque sacrificed Torres for target man Fernando Llorente just before the hour mark.
In the 60th minute there was nearly an immediate impact as Llorente's diving header from Sergio Ramos' cross was somehow saved by Eduardo at point-blank range, before Villa curled one just wide.
The breakthrough came seconds later. Typically intricate build-up play saw Andres Iniesta feed Xavi who backheeled beautifully to the on-rushing Villa. The striker saw his first shot saved well by Eduardo but hammered the rebound high into the net.
Eduardo then got down brilliantly to turn away Ramos' drive from the right before Queiroz sent on striker Liedson and midfielder Pedro Mendes.
Again Eduardo was called upon to parry a shot, this time from Villa, while at the other end Portugal talisman Ronaldo was dreadfully quiet.
Villa's cross enabled Llorente to head just wide before the goalscorer was taken off for a rest, replaced by Pedro.
Danny had a dangerous-looking shot blocked well by Pique but moments later Portugal were down to 10 men when referee Hector Baldassi suddenly produced a red card, for defender Costa, for apparently lashing out at Joan Capdevila.