Real Sociedad won a tight game at Deportivo La Coruna 1-0 to secure its place in the Champions League and send its opponent tumbling out of La Liga's Primera Division on the final day of the season Saturday.
Antoine Griezmann scored the only goal for Sociedad, which also had Markel Begara sent off late on, and the win coupled with Valencia's 4-3 defeat at Sevilla ensured a top-four finish.
Alvaro Negredo scored all four Sevilla goals in a seven-goal thriller that saw Valencia finish just outside the Champions League places. Valencia finished the season in fifth and earned a place in the Europa League after goals from Ever Banega and a Roberto Soldado double were not enough to secure the win it needed to claim the fourth spot.
Valencia manager Ernesto Valverde announced he would be leaving this summer after taking the club over in December on a six-month contract.
For Sevilla, the ninth-placed finish this win provided could also see it compete in the Europa League next season, assuming European bans to Malaga and Rayo Vallecano are upheld upon appeal.
Real Betis secured Spain's other Europa League spot after a 1-1 draw with Levante ended an impressive season with Betis in seventh place.
At the other end of the table, Depor's loss left it in 19th place, relegating it along with 18th-placed Real Mallorca and last-placed Real Zaragoza.
Celta Vigo escaped relegation with a 1-0 win over Espanyol. Natxo Insa struck after 15 minutes as the home side avoided the drop to the delight of a packed Balaidos as overjoyed fans swarmed on to the pitch at the final whistle.
Mallorca beat Real Valladolid 4-2 but it was not enough to prevent relegation on a tense final day. Mallorca will play in the Segunda Division next season for the first time since 1997.
Mexico international Giovani Dos Santos scored for Mallorca, one day after a Mexican national team offical said his club was "kidnapping" him and preventing him from reporting for national team duty before Saturday's game.
Zaragoza's four-year stay in the Primera Division ended as it slipped to a 3-1 defeat at the hands of Atletico Madrid in a game where all the scoring came in the final six minutes.
Arda Turan's late strike appeared set to decide the contest in Atletico's favor. But Helder Postiga equalized in the 89th minute, but a miserable night for the hosts at La Romareda was capped by two injury-time goals from Diego Costa.
Atletico was assured of third place before kick-off and this result means it ends the campaign with the best away defensive record in the league.
Elsewhere, Getafe's faint hopes of European football melted away as it finished with a 2-0 defeat away to Granada, and Rayo Vallecano was forced to settle for an eighth-placed finish after being held 2-2 at home by an Athletic Bilbao side that played almost the entire match with 10 men.
Information from Press Association was used in this report.