Spain secured third place at the Confederations Cup on Sunday when Xabi Alonso curled home a long-range free kick to give them a 3-2 win over hosts South Africa after extra time.
Alonso's 107th minute effort evaded both his own strikers and the home defence to settle a thrilling match that produced several twists.
South African substitute Katlego Mphela forced the game into extra time with a ferocious free kick at the end of 90 minutes, having put the team in front in the 73rd.
Goals in the 88th and 89th minutes from Daniel Guiza had put the European champions 2-1 up heading into stoppage time.