Real Sociedad claimed a place in the Champions League despite a 2-1 defeat at Atletico Madrid in La Liga on Sunday.
Fifth-placed Villarreal's loss at Rayo Vallecano by the same scoreline meant Sociedad could not be caught in fourth spot.
Antoine Griezmann and Nahuel Molina were on target for Atletico at the Civitas Metropolitano with Alexander Sorloth hitting a late reply for the visitors.
Atletico's victory took them back within a point of second-placed city rivals Real Madrid.
Raul de Tomas and Isi Palazon struck either side of the hour-mark for Rayo Vallecano against Villarreal at the Vallecas Stadium. Giovani Lo Celso gave the Yellow Submarine hope seven minutes from time but it was not enough.
At the other end of the table, Espanyol were relegated after conceding a late equaliser to draw 2-2 at Valencia.
Samuel Lino struck three minutes into added time to seal Espanyol's fate after they had replied to Diego Lopez's opener with goals from Cesar Montes and Martin Braithwaite.
Valladolid remain in the bottom three with a game remaining after drawing 0-0 with another troubled side, Almeria, who are just a point above them.
Cadiz boosted their survival hopes with a 1-0 win over fellow strugglers Celta Vigo and Getafe did likewise as they saw off Osasuna 2-1.
Champions Barcelona, meanwhile, extended their unassailable lead at the top of the table to 11 points with a 3-0 win over 10-man Mallorca at the Nou Camp.
Ansu Fati opened the scoring in the first minute before doubling the lead after the dismissal of Mallorca's Amath Diedhiou. Gavi wrapped up the win 20 minutes from time.
Sergej Milinkovic-Savic struck an 89th-minute winner as Lazio moved back into second place in Serie A with a 3-2 victory over relegated Cremonese.
It was the Serbian's second of the game at the Stadio Olimpico with Elseid Hysaj also on target for the Rome side.
Cremonese had hit back from 2-0 down through Pablo Galdames and a Manuel Lazzari own goal.
Hellas Verona remain in the bottom three after conceding a stoppage-time equaliser to draw 1-1 with Empoli.
The hosts had led at the Marcantonio Bentegodi Stadium through Adolfo Gaich but Giangiacomo Magnani turned into his own net in the sixth minute of time added on.
Their survival fight will still go to the final day, however, with the result having pulled them level on points with Spezia.