Malaga earn first shot at Champions League
The last eight matches had three places in Europe and two relegation slots at stake as the games all kicked off at the same time with fans glued to their radios in grounds around Spain.
Salomon Rondon headed Malaga in front from a corner just after half-time, putting the big-spending club on 58 points ahead of Atletico Madrid and Levante who finished fifth and sixth to secure entry to the Europa League.
"The dressing room are delighted. We weren't content to settle for a Europa League place," Malaga coach Manuel Pellegrini, who took over midway through last season, told a news conference.
"Malaga have beaten many institutions that are much stronger than we are. We are going to start to experience many new things, and need to be prepared in many different areas. This is a five-year project."
Atletico beat Villarreal 1-0 with an 88th-minute header from Radamel Falcao, the hero of their midweek Europa League final win over Athletic Bilbao, and condemned the team that finished fourth last season to relegation.
Villarreal were hanging by a thread in 17th when news filtered through that Rayo Vallecano had grabbed a 90th-minute winner through Raul Tamudo, for a 1-0 victory over Granada.
Rayo pushed Villarreal, the Champions League semi-finalists in 2006, down into the second division and a pitch invasion at their tiny stadium saw players being stripped of their kit.
"It's very tough," Villarreal defender Angel told Spanish television as he left the pitch at the Madrigal.
"Football is like this. Sometimes strange things happen. We have to try and pick ourselves up. This is football."
Real Zaragoza escaped from the bottom three with a 2-0 victory at Getafe who finished with eight men on the pitch.
Levante secured their highest league finish in their 102 years with a 3-0 rout of Europa League finalists Bilbao, and qualified for European competition for the first time.
Abdelkader Ghezzal scored twice and Francisco Farinos grabbed a late penalty to cap a remarkable campaign for the small club from Valencia, who had been expected to be battling to avoid relegation.
Champions Real Madrid signed off with a 4-1 hammering of Real Mallorca at the Bernabeu to set a new La Liga record of 100 points for a season, beating the previous best of 99 achieved by Pep Guardiola's Barcelona in 2010.
Cristiano Ronaldo, headed his 46th league goal of the campaign, Karim Benzema and a double from Mesut Ozil lifted Real to a league scoring record 121 goals.
Real ended nine points ahead of deposed champions Barcelona, who signed off with a 2-2 draw at Real Betis on Saturday.
Valencia were 30 points back in third in the last automatic qualification Champions League slot despite losing 1-0 at Real Sociedad on Saturday.