Spain 1-0 Portugal
David Villa's fourth goal at SA 2010 broke Portuguese hearts but kept Spain on course for their first ever World Cup triumph
Portugal, who had not conceded a goal in their previous three games at the tournament, frustrated their Iberian neighbours for more than an hour before Villa's 63rd minute effort.
And to compound a miserable night for Carlos Queiroz's side, Portugal finished with 10 men after Ricardo Costa was sent off after clashing with Joan Capdevila.
But it was not all good news for Spain - or Liverpool.
Fernando Torres has looked like a man who has had two knee operations in the past few months at this World Cup.
Two years to the day since his goal ended 44 years of hurt for Spain by winning Euro 2008, Torres started against Portugal despite some lacklustre performances in South Africa.
But after a first minute effort that required a fine save by Eduardo, the Liverpool striker faded badly and was replaced with more than half an hour of the game remaining.
There has to be some doubt whether Torres, who is clearly out of sorts, will feature in Saturday's quarter-final with Paraguay in Johannesburg.
Fortunately for Spain, however, Villa looked decidedly more threatening.
He tormented and teased Portugal's defence throughout and caused countless problems.
But this was by no means a one-sided contest.
Portugal almost broke the deadlock with their first serious attack midway through the first half.
After a brilliant run, Fabio Coentrao teed up Tiago, whose 25-yard blast was pushed into the air by Iker Casillas.
Spain's keeper was forced to make a quick recovery with Hugo Almeida threatening to pounce.
Casillas produced another nervous performance between the posts, and was lucky to escape after spilling a 35-yard free-kick from his Real Madrid team-mate Ronaldo in the 29th minute.
Although Spain enjoyed plenty of possession, they struggled to breakdown a well marshalled Portuguese defence.
And it was the Spanish who were looking vulnerable when Almeida got his head on the end of Simao Sabrosa's dangerous cross yet somehow failed to find the target from six-yards.
After Carles Puyol almost found his own net, Spain burst into action with Villa finally providing the breakthrough with an effort which went in off the woodwork after great play by Xavi.
Portugal were disappointing in qualifying. They have been just as disappointing in South Africa.
They bowed out with 10 men after Costa was involved in an off-the-ball incident with Joan Capdevila with two minutes remaining.
Spain (4-5-1): Casillas; Ramos, Pique, Puyol, Capdevila; Alonso (Machena 90), Xavi, Iniesta, Busquets, Villa (Pedrito 87); Torres (Llorente 58).
Subs (not used): Reina, Valdes, Albiol, Arbeloa, Fabregas, Javi Martinez, Silva, Navas, Mata.
Portugal (4-5-1): Eduardo; Alves, Costa, Carvalho, Coentrao; Simao (Liedson 72), Meireles, Pepe (Mendes 72), Tiago, Ronaldo 6; Almeida (Danny 58).
Subs (not used): Beto, Fernandes, Ferreira, Rolando, Miguel, Duda, Veloso, Amorim, Deco