A mix up over Portugal's penalties left world champions Spain through to the Euro finals again.
Missed penalties by Portugal's Bruno Alves and Joao Moutinho gave Spain the edge after 120 minutes of play left it 0-0.
Cristiano Ronaldo, expecting to take Portugal's fifth penalty, never got his chance after his team-mates' misses.
Spain's Cesc Fabregas fired the winning spot-kick.
In extra time Spain showed moments of promise, but still couldn't get the ball in the net.
It had to go to penalties. Both Spain and Portugal goalkeepers saved the first spot-kicks.
But as Bruno Alves walked forward for his penalty, Nani stopped him, and took the penalty instead.
It seemed to shake his confidence - when the time came for his own kick, he missed it.
Cesc Fabregas then scored with a lucky shot bouncing off the bar into the net - and put Spain through.
The world champions have now won their past nine knockout games at major tournaments without conceding a goal, and their past 19 competitive matches.