Striker, Alvaro Morata grabbed a dramatic winner as Spain beat Portugal 1-0 in Group A2 to qualify for the UEFA Nations League Finals.
Morata scored in the 88th minute from close range after Nico Williams headed the ball into his path.
Portugal only needed a point to advance and had chances to score but Diogo Jota and Cristiano Ronaldo both missed opportunities.
They began the night top of Group A2 and will be wondering just how they failed to book their place at next summer’s four-nation tournament.
An excellent pass from Bruno Fernandes was collected by Jota, who shot at goal but was denied by a fine one-handed save by Spain’s goalkeeper, Unai Simon.
Portugal continued to create the better opportunities with Fernandes hitting the side-netting, and Ronaldo having a shot blocked by Simon early in the second half.
Substitute, Williams made a difference for Spain and twice had efforts saved by goal-keeper, Diogo Costa.
But Costa was beaten with only two minutes remaining when Williams’ header went past him with Morata hooking the ball into the roof of the net from close range.
Portugal won the inaugural competition in 2018-19, and were the better team for most of the match in northern Portugal.
Spain will be joined in next June’s finals by Croatia, Italy and the Netherlands, who are expected to host all the matches.
Portugal, whose team included Bruno Fernandes and Cristiano Ronaldo, won the first Nations League in 2019.
Spain were runners-up in the Nations League Finals in 2021 and now have a chance to win the tournament in June next year.