(CNN) -- Spain needed an injury-time goal from substitute Fernando Llorente to beat Saudi Arabia 3-2 in a World Cup warm-up match in Innsbruck on Saturday.
It was a less than convincing performance in Austria for the European champions, who are among the favorites for next month's World Cup.
Osama Hawsawi gave Saudi Arabia a shock 16th minute lead before David Villa and Xabi Alonso scored to put Vincente Del Bosque's men ahead.
But Mohammed Al-Sahlawi's 74th-minute equalizer -- his deflected shot caught Iker Casillas off balance -- appeared enough to have earned his side a draw.
However, Athletic Bilbao striker Llorente, who came on for Villa with 20 minutes remaining, had the final say.
He connected with Alonso's corner with a firm header to give Spain a last-gasp victory.
Spain face a testing encounter against fellow finalists South Korea on June 3 before they kick off their World Cup campaign with a Group H match against Switzerland on June 16.
Honduras and Chile are also in the group.
Germany continued their build-up to the finals with an impressive 3-0 win over Hungary in Budapest.
Lukas Podolski opened the scoring with a fourth minute penalty before Mario Gomez scored the second midway through the second half.
Brazilian-born Cacau then came off the substitutes' bench to score the third. It was his third in two games for his adopted country after a double against Malta and presses his claims for a place in the World Cup squad.
Germany coach Joachim Loew must cut two players to trim it down to 23 and said it was not an easy decision.
"The coaches will sit down together on Sunday and Monday with the coaching staff and announce the squad on Tuesday.
"Of course, it will hurt for the players concerned, but unfortunately we can only take 23," he told AFP.
The United States, who play England in their opening game of the finals, beat Turkey 2-1 in Philadelphia.
A crowd of more than 55,000 at Lincoln Financial Field saw Arda Turan open the scoring after 27 minutes for the visitors.
But Jozy Altidore equalized just before the hour mark and Fulham striker Clint Dempsey grabbed the winner with 15 minutes remaining after an assist from Landon Donovan.
Earlier, Serbia's preparations suffered a setback in a 1-0 defeat to New Zealand, who are also heading to South Africa.
The match in Klagenfurt in Austria was decided by a goal from Shane Smeltz in the 22nd minute.
He beat Serbia goalkeeper Vladimir Stojkovic with a low shot to notch his 16th goal in 29 games for the All-Whites.
The result is setback for Serbia, who face Australia -- winners over their neighbors last week -- in Group D in South Africa, as well as Germany and Ghana.
New Zealand are in Group F with Italy, Paraguay and Slovakia.