A goal by striker David Villa earned Spain a 1-0 win over neighbours Portugal and a World Cup quarter-final place after an entertaining match on Tuesday in which the Portuguese also created several chances.
The alert Villa struck the winner after 63 minutes when he fired the ball into the net off the underside of the bar after his first effort was blocked by excellent goalkeeper Eduardo, having been set up by Xavi's clever back-heel in the area.
Portugal right back Ricardo Costa was sent off in the 90th after a clash with Joan Capdevila on the edge of the area.
Spain, the European champions, will meet Paraguay, who earlier won a penalty shootout against Japan after a 0-0 draw, in the quarter-finals.
Spain had started the game stronger, dominating possession in the early moments, with forwards Fernando Torres and Villa forcing Eduardo to palm away three long distance efforts from the left wing in the first seven minutes.
Portugal right back Ricardo Costa composed himself after a torrid start but his side were still unable to keep possession. The Spanish, however, did not make use of their control, rarely able to send a decent ball into the box.
Portugal's first chance came in the 20th minute. After good play from lively left back Fabio Coentrao, Tiago's drive was punched high by Iker Casillas and the Spain keeper did well to beat the tall Hugo Almeida to the ball as it came down.
Portugal winger Cristiano Ronaldo had been lively, though mostly ineffective, but nearly scored a stunning goal with a fierce, swerving free kick from almost 40 metres that hit a confounded Casillas in the chest and arms and flew to safety.
Portugal almost went ahead five minutes after halftime, Almeida winning some space on the left and attempting to feed the incoming Ronaldo, but his cross deflected off Carles Puyol's knee and flew inches wide of the Spanish post.
Torres was not providing the sort of menace expected of him, and he was replaced in the 58th minute by Fernando Llorente, who took only two minutes to create danger, his flying header from a Sergio Ramos cross kept out by Eduardo.
Spain came close once more moments later when Villa sent a curling shot just wide, but the lethal striker was not to be denied and he grabbed his goal with his next effort.Portugal failed to respond immediately and almost suffered again after 70 minutes when Ramos beat Coentrao and fired a low diagonal shot that was tipped for a corner by the keeper.