Barcelona closed out its third straight league crown in style as a team made up mostly of reserves recovered for a 3-1 victory at Malaga on Saturday, while Cristiano Ronaldo scored twice in Real Madrid's 8-1 thrashing of Almeria to set a Spanish league scoring record.

While the top two both finished off with victories, Deportivo La Coruna lost 2-0 to Valencia to be relegated into the second division for the first time in 20 years, joining Hercules and Almeria.

Deportivo was among six teams in risk of going down on the final day and Aritz Aduritz's fourth-minute goal left it in a desperate situation early at El Rizaor Stadium. Roberto Soldado added the second goal in the final seconds.

Deportivo, which won one league and two Copa del Rey trophies after coming up in 1991, set a record for relegated teams with 43 points.

''We tried everything, what more can we do? We created chances but the ball didn't want to go in,'' said Deportivo forward Juan Carlos Valeron.

Zaragoza ensured it stayed up with a 2-1 win at Levante, Getafe and Real Sociedad both remained after a 1-1 draw, and Osasuna beat Villarreal 1-0 to ensure its spot.

Mallorca finished 17th and in the last topflight spot despite Sergio Aguero's hat-trick guiding Atletico Madrid to a 4-3 win. Mallorca fans invaded the Juegos Mediterraneos Stadium field to celebrate, while at Deportivo supporters wept in the stands.

At the Santiago Bernabeu, Ronaldo poked home after just four minutes to break the record before striking again in the 77th with a hard shot past goalkeeper Esteban Suarez to set a new mark of 40 goals in a single season. Ronaldo had shared the mark of 38 with Athletic Bilbao's Telmo Zarra and Madrid's Hugo Sanchez, the league scoring leaders from the 1950-51 and 1989-90 seasons.

''To score so many goals in a season is very hard. I have to thank my teammates,'' Ronaldo said. ''The (scoring title) is for them and the fans too.''

Emmanuel Adebayor scored a hat trick while Karim Benzema also added a brace as Madrid routed already-relegated Almeria to take its goal tally for the season to 102 from 38 games.

Madrid finished four points behind Barcelona, which recorded its league record 14th victory in 18 away games to finish its 21st title-winning season with 96 points.

Bojan Krkic's penalty just before half time canceled out Sebastian Fernandez's 31st-minute opener for Malaga before Ibrahim Afellay and Marc Bartra scored late second-half goals eight minutes apart to secure victory.

Afellay made amends for spoiling an earlier solo chance by cutting into the middle to curl a long-range strike beyond goalkeeper Willy Caballero in the 76th.

Bartra scored his first goal with the senior team as the defender found himself alone inside the area to turn substitute Daniel Alves' corner home with a well-guided header.

''We're not here to grade ourselves, we're here to play a game and that's been impeccable,'' Barcelona coach Pep Guardiola said. ''Last year we had 99 points and this year 96 - it's absolutely ridiculous.''

Lionel Messi was among seven regulars left out of the squad to rest up for next Saturday's Champions League final against Manchester United at Wembley.

Ronaldo moved ahead of Messi with 53 goals overall on the season with his second strike at the Santiago Bernabeu after he opened by poking home Sergio Ramos' header.

Jerzy Dudek was given a rare start as the Polish goalkeeper played his last game for Madrid, while Adebayor showed he will be missed if the Togo striker leaves the club when his loan-spell from Manchester City expires.

Jose Luis Samartin also scored his first goal for Madrid soon after coming on as a late substitute. Kalu Uche had pulled Almeria to within 2-1 before Madrid exploded in the second half.

''For a defensive team that doesn't play football, to pass 100 goals is good,'' assistant coach Aitor Karanka said, making light of the criticism aimed at Jose Mourinho's tactics.

Sevilla finished fifth thanks to a 3-2 win at Espanyol, while Athletic Bilbao joins it in the Europa League after ending the season sixth with a 2-1 victory at Racing Santander. Atletico finished seventh for the last European spot but will have to go through Europa League qualifying.

Also in the final round, it was Hercules 0, Sporting Gijon 0.

Second division leader Real Betis has already assured its place in the top division.