Reigning European and world champions Spain needed a last-gasp Jesus Navas goal to draw 2-2 with Chile in a friendly in the Swiss city of Geneva on Tuesday.
With neither side in World Cup qualifying action, they met in a repeat of a 2011 friendly, in which Spain came from behind to win 3-2.
On this occasion, Vicente del Bosque's side twice trailed before coming back to draw, with Eduardo Vargas netting Chile's two goals and Roberto Soldado and Navas on target for Spain.
Having come close to Spain's first-ever loss to Chile, del Bosque lauded his side's opponents.
"I wasn't surprised by their quality," the veteran Spain manager said.
"They were far more active, and literally a cut above us. We could have started with more intensity, but I was pleased with the final part of the match," he said.
"We were able to use this match to test players who have seen less action recently. We'll be drawing our conclusions," he added, without elaborating.
Chile's Argentine coach Jorge Sampaoli was upbeat after coming nail-bitingly close to an exploit.
"We were fully aware that we were facing the best team in the world. I'm more than satisfied with this performance. The result isn't the main thing," said Sampaoli, whose side remain on track to qualify for next year's World Cup finals.
"The lads were great. They stood eye to eye with Spain. I'm proud. And pride beats disappointment. They exceed all expectations," he added.
Switzerland is home to sizeable communities from both Spain and Latin America, but the smaller Chilean contingent outsung and outdrummed the Spanish fans in the Stade de Geneve.
Roared on by their supporters, Chile took the game to Spain from the outset.
Their efforts paid dividends fast, as Vargas latched onto the ball and launched a powerful fifth-minute strike from the centre of the box, beating Spanish keeper Victor Valdes, given his chance in goal at the expense of Real Madrid's Iker Casillas.
Spain drew level in the 37th minute, however, with Pedro Rodriguez finding Tottenham Hotspur striker Soldado, who headed the ball past Claudio Bravo, the Chile 'keeper who plies his trade in La Liga with Real Sociedad.
There was still time for Vargas to restore Chile's lead a minute before the interval with a finish that was similar to his first goal, but once back from the dressing room, Spain looked hungry to take control.
Andres Iniesta came close to equalising soon after the restart before substitute Alvaro Negredo failed to make contact with the ball as he lunged on the line.
But, just when it looked like it was not to be Spain's night, they struck in stoppage time, Pedro helping the ball on for Navas to convert at the near post and deny Chile a historic win against La Roja in the process.