Jose Salomon Rondon's second-half header was enough to secure Malaga Champions League football for the first time in their history and ensure that Sporting Gijon were relegated after a narrow 1-0 win.
The hosts dominated from start to finish and only a combination of some fantastic goalkeeping from Juan Pablo, poor finishing and the woodwork managed to keep the score down.
Rondon came within inches of opening the scoring midway through the first half as his header came back off the post, but the Venezuelan made no mistake four minutes after half-time as he rose highest to power home Santi Cazorla's corner.
Pablo then twice denied Ruud Van Nistelrooy with smart stops and Rondon also passed up two clear opportunities but Malaga were untroubled when Isco was shown a second yellow card with two minutes remaining.
Villarreal tumbled out of the Primera Division after losing to Atletico Madrid while relegation rivals Real Zaragoza and Rayo Vallecano both won.
The Yellow Submarine, who finished fourth last season, saw a dismal season end in disappointment as Radamel Falcao's 88th-minute goal enabled Europa League winners Atletico to win 1-0 at El Madrigal.
Zaragoza started the day in the bottom three but were 2-0 winners at eight-man Getafe.
The real escape story came in Madrid, however, with Rayo leaving it until injury time to beat Granada courtesy of Raul Tamudo's dramatic effort.
Sporting Gijon will also play second tier football next season as their unlikely bid to avoid the drop ended in failure after a 1-0 defeat at Malaga, who secured fourth and a Champions League spot as a result.
On Saturday, Seydou Keita's injury-time equaliser ensured Pep Guardiola's final Primera Division game as Barcelona manager was not marked by defeat as his side drew 2-2 at Real Betis.
Sergio Busquets put Barca ahead in the ninth minute of a first half they dominated but Betis responded well in the second half and they took advantage of Dani Alves' sending off in the 53rd minute.
The impressive Ruben Castro scored two sublime goals in three minutes and Betis were on course for victory before Keita headed home 90 seconds into injury time.
Real Sociedad ended the season on a high as Antoine Griezmann's second-half goal saw off Valencia.
With both sides having little to play for, the game started slowly, but it improved improved after the break as Aritz Aduriz and Pablo Hernandez passed up chances to give the visitors the lead.
Instead Sociedad got the winner midway through the second half as Griezmann slid in to meet Xabi Prieto's cross for his third goal in four games to seal a 12th-placed finish for the Basques, their best in the top flight since coming second in 2003.