Germany inflicted Spain's first home defeat under manager Vicente del Bosque as Toni Kroos's late goal proved enough for the world champions.
The Real Madrid midfielder saw a low shot from 20 yards fumbled into the net by substitute goalkeeper Kiko Casilla, who was making his debut.
It was a friendly of little quality, with Bayern Munich forward Thomas Muller limping off through injury in the first half.
Spain debutant and Celta Vigo forward Nolito went closest for the hosts, seeing a 20-yard shot turned away by goalkeeper Ron-Robert Zieler.
Germany had lost their three previous encounters against Spain, including the Euro 2008 final and the World Cup 2010 semi-final.
Del Bosque, who has been Spain boss since 2008, saw his side knocked out of the World Cup in the first round in Brazil and a defeat to Germany caps a miserable year.
Neither side looked threatening for much of the match with both restricted to long-range efforts.
But, in the end, an error from Espanyol's Casilla proved decisive for the the top-ranked team in the world.
Spain were previously unbeaten in the seven matches they had played at Celta Vigo's Balaídos stadium.