Spain qualified for the Nations League Finals with a dramatic win over Portugal.
He scored in the 88th minute after the ball was headed his way.
Portugal only needed a point to advance, but they missed two chances to score.
The finals will be hosted by Croatia, Italy, and the Netherlands.
Portugal started the night top of Group A2 and will be wondering how they didn't get into the tournament.
The team that won the inaugural competition was the better team for most of the match.
Jota shot at goal but was denied by a one-handed save by Spain's Unai Simon.
The hosts continued to create the better chances, with Fernandes hitting the side-netting and a shot blocked by Simon early in the second half.
Williams made a difference for Spain and twice had his efforts saved by Costa.
The Portugal goalkeeper was beaten with only two minutes remaining when Williams headed the ball into the roof of the net.
Spain have a chance to win the tournament in June after finishing second in the Nations League finals.