A goal by striker David Villa earned Spain a 1-0 win over neighbours Portugal and a World Cup quarter-final place.
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 minute for catching Spain defender Joan Capdevila in the face with an elbow as the pair tussled 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 last eight at Ellis Park on Saturday.
"We felt comfortable but you have to be careful because things can change quickly," said coach Vicente del Bosque. "We know we're working well, we want to create a bit of history."
Portugal coach Carlos Queiroz added: "Spain were much more effective moving the ball around. We were looking for chances on the counter-attack. We had our chances, we just didn't score. We showed ambition and desire to win but it just wasn't possible. We'll have to come back stronger."