A late goal by Real Sociedad substitute Adnan Januzaj secured a 1-1 draw at Atletico Madrid on the final day of the La Liga season as they finished sixth to secure a Europa League spot.
The draw left third-placed Atletico on 70 points, 17 adrift of champions Real Madrid and 12 behind Barcelona. They will be joined in next season's Champions League by already qualified fourth-placed Sevilla, who beat Valencia 1-0.
Granada hammered Athletic Bilbao 4-0 to grab seventh place and a spot in the Europa League second qualifying round.
The third Europa League spot is usually awarded to the winners of the Copa del Rey but instead went to the team finishing seventh as finalists Real Sociedad and Athletic Bilbao requested that the showpiece, postponed due to the COVID-19 pandemic, be postponed until next season so fans can attend.
Needing only a point to make it into Europe next season, Real Sociedad's dream was almost shattered when an outrageously brilliant backheel from Atleti's Alvaro Morata teed up the ball for Koke to blast home on the half-hour mark.
However, Januzaj's free kick three minutes from time flew into the net, securing Sociedad a place in Europe next season.
"At halftime I told the players we were going to do it and in the 80th minute, and we scored in the 86th. The team never stopped believing and I think by finishing sixth justice has been done," said Sociedad coach Imanol Alguacil.
"I feel terribly proud to be coach of this great club and for getting into Europe and for the way we did it."
Roberto Soldado got Granada off the mark in the 29th minute and second-half goals from Antonio Puertas, Carlos Fernandez and Angel Montoro helped them breeze past Bilbao. They finished with 56 points.
Villarreal had already secured fifth place in the standings and qualification for the Europa League group stage.
Getafe, meanwhile, missed out on Europe after a remarkable 1-0 defeat at Levante in which they had three goals ruled out by VAR, missed a penalty and conceded an added time strike.
The Madrid side, who face Inter Milan in the last 16 of this season's Europa League, finished in eighth place on 54 points.
"Today football has been very unfair on us and we leave feeling very sad because we had it in our hands and let it escape on the last day," said Getafe coach Jose Bordalas.
"Angel Rodriguez's goal should have stood and Jaime Mata has scored so many penalties and then look what happens."