South Africa deserved to win at Soccer City in Johannesburg, with Vicente del Bosque's side disjointed throughout, rarely testing Itumeleng Khune in the home goal.
After a first half of few chances, Bernard Parker struck the only goal of the game, latching on to a throughball and finishing well, Nacho Monreal unable to save his side, despite an acrobatic attempted clearance.
Goalkeeper Victor Valdes had entered the game at half-time, but was forced from the pitch with a painful looking knee injury that forced him from the field.
Del Bosque made 10 changes to the side that edged past Equatorial Guinea 2-1 on Saturday, Xabi Alonso the only man retained, while four of South Africa's XI from their 3-0 triumph over Swaziland were again picked by Gordon Igesund.
Spain looked to exploit the hosts' high defensive line with David Villa finding the net twice in the opening seven minutes, only to be denied by the offside flag.
South Africa grew in confidence after their shaky start and almost took the lead through Oupa Manyisa in the 17th minute.
The Orlando Pirates midfielder picked the ball up 30 yards out and crashed an effort at goal that deflected off Sergio Ramos and looped over a stranded Iker Casillas but bounced over via the crossbar.
After a promising start, the half fizzled out into a scrappy affair with Alonso whipping a low free-kick wide and Bongani Khumalo crashing a header wide of the near post with the last action of the opening period.
Tokelo Rantie blazed a gilt-edged chance over two minutes into the second period, while Andres Iniesta brought a smart save from Khune, but it was the hosts who took a shock lead in the 56th minute.
Thabo Matlaba burst up the left wing before neatly finding Parker, who dinked over substitute goalkeeper Valdes with Monreal unable to prevent the goal.
A raft of substitutions seemed to have only further dented Spain's fluidity and there was further cause for concern as Valdes was forced off with 15 minutes to go, appearing to injure his knee in innocuous circumstances.
Pepe Reina became Spain's third keeper of the night, after a lengthy delay as South Africa fumed over the visitors' attempts to use a seventh change of the game - the most permitted for a friendly is six.
Del Bosque could only watch on as his side failed to draw level, Khune denying Raul Albiol's toe-poked effort in the last minute of stoppage time as Spain slipped to their first loss since July's 3-0 FIFA Confederations Cup final loss to Brazil.
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.