Defeat means Spain must win their next two group matches or face an early exit.
Switzerland tore up the World Cup script with the biggest shock of the tournament when they beat Spain 1-0 on Wednesday, their first victory over the Spaniards in 19 attempts.
Spain came into the match with a swagger on the back of a perfect qualifying campaign, a run of 12 straight victories and as favorites to win the tournament.
They departed the Moses Mabhida stadium potentially facing a tricky second round tie against five times champions Brazil, newly installed as favorites in their place.
Gelson Fernandes scored the scrappy winner in the 52nd minute and Spain, for all their talent and guile, were unable to find a way through the massed ranks of white Switzerland shirts.
Vincente del Bosque, coach, Spain, said: "We tried in an orthodox way and in an heroic way but we were not able to score. It wasn't our day. We dominated almost all the match."
He added: "This defeat means that we have to win the other two (group) matches."
The Swiss, who have not conceded a World Cup goal since a 3-0 defeat to Spain in 1994, share the lead in Group H with Chile, who beat Honduras 1-0 earlier on Wednesday.
Ottmar Hitzfeld, coach, Switzerland, said: "It's a great feeling to start the tournament with three points against one of the biggest contenders for the title."
He added: "These were three unexpected points and beyond that I was very pleased to see a strong performance by my team. I'm very happy, I'm very satisfied by this excellent start."
After a forgettable first half, the Swiss looked like spending another 45 minutes defending for their lives until goalkeeper Diego Benaglio's long punt caused chaos in the Spanish defense.
Goalkeeper Iker Casillas clashed with Swiss striker Eren Derdiyok and Gerard Pique was unable to stop the ball falling to Fernandes, who clipped it into an empty net.
Speaking to reporters after the game, the Cape Verde Islands born midfielder said: "To be fair I'm not used to scoring goals so it was a surprise. It was a bit of luck you know."
The European champions enjoyed a near monopoly of possession for much of the game but were profligate in front of goal and unable to beat the impressive Benaglio.
Del Bosque, who had started the match with David Villa as a lone striker, brought forwards Fernando Torres, Jesus Navas and Pedro to try and rescue the game but a virtual siege of the Swiss penalty area failed to produce an equalizer.
Xabi Alonso hit the underside of the bar with a fine strike in the 70th minute, Navas shot lamely at Benaglio when through on goal about a minute later, and Pique squandered another chance on the next Spanish attack.
Derdiyok, playing in place of his injured captain Alex Frei, then jinked his way through the defense to almost double the Swiss lead but, to the relief of the Spanish, his shot came bouncing back off the post.
Torres had a couple more openings in the dying minutes of the game but failed to exploit them and, after five minutes of added time, the Swiss were able to celebrate a famous upset. (Reuters)