El Salvador 0-2 Spain
Diego Costa made a successful comeback from injury as David Villa scored twice to give Spain victory over El Salvador in their final World Cup warm-up game.
The striker played for 73 minutes and was fouled for an early penalty which Cesc Fabregas missed.
Villa came off the bench to increase his record goal tally for Spain to 58.
The 32-year-old, who announced this week he was leaving Atletico Madrid to join Major League Soccer team New York City, headed in after an hour and then fired home in the sixth minute of injury time.
"We know that Villa, in tight spaces, is one of the best forwards in the world," said coach Vicente Del Bosque.
"The feelings are good and we are optimistic about the start of the competition."
Spain start their World Cup campaign against the Netherlands on 13 June and also face Chile and Australia in Group B.