Real Madrid clinched its 32nd Spanish league title and first in four years on Wednesday, overshadowing Lionel Messi breaking a 39-year European club scoring record by hitting a hat trick to take his season total to 68 goals.

Madrid won 3-0 at Athletic Bilbao for its first league championship since 2008, forcing Barcelona to relinquish the title after three straight years despite winning 4-1 against Malaga in which Messi scored three goals for the ninth time this season.

Madrid's players celebrated wildly after the final whistle at San Mames stadium, with coach Jose Mourinho displaying seven fingers to symbolize the number of league titles he has won in his career, including at FC Porto, Chelsea and Inter Milan.

"This was the most difficult one," said Mourinho, who team has a seven-point lead over Barcelona with two rounds left.

Madrid's squad will officially celebrate in the Spanish capital on Thursday after finally getting the better of a Barcelona team that has dominated Spanish and European football since coach Pep Guardiola's arrival in 2008.

"The players are all very happy after 10 months of fighting, of training, of games, the objective was to be champion so we are happy to have achieved it," Cristiano Ronaldo said. "To have beaten a team like Barca makes this league win more difficult. It's much better to win against one of the best teams — it makes it better."

Gonzalo Higuain scored for Madrid in the 16th minute and Mesut Oezil doubled the lead four minutes later. Ronaldo added his 58th goal of the season in the 50th — and the club's record 115th this campaign — to make up for a penalty in the 12th that was saved by goalkeeper Gorka Iraizoz.

Messi broke the record of 67 goals Gerd Mueller set for Bayern Munich in 1972-73. He converted penalties in the 35th and 59th minutes and chipped goalkeeper Carlos Kameni in the 64th for his seventh league hat trick, tying the mark set by Ronaldo this season.

The 24-year-old Messi has played 57 games for Barcelona this season, and broke records by scoring 46 goals in the league and 14 in the Champions League.

But while Barcelona celebrated Messi's scoring feats, Madrid's famous Plaza de Cibeles began filling with fans in anticipation of Madrid celebrating the end of its great rival's league dominance and yet another title for Mourinho.

Ronaldo also missed a penalty in the Champions League semifinal shootout loss to Bayern Munich last week, and his weak spot kick on Wednesday was easily stopped by Iraizoz to give supporters some early concern.

But Higuain's impressive goal — his 22nd this season — put Madrid on course for victory and Oezil made it 2-0 soon after.

Ronaldo made amends for his miss with a header with Athletic reduced to 10 men in the 72nd after Javi Martinez was sent off for a second booking.

Golden Boots

"I have two Golden Boots at home. So if I win the third, great. If not, not a problem," said Ronaldo of the race to finish as Europe's leading scorer.

At the Camp Nou, Carles Puyol's 13th-minute opener for Barcelona was cancelled out by Jose Rondon for Malaga.

Iniesta was fouled inside the area to set up Messi's 34th-minute spot kick that matched the 66-goal tallies by Pele for Brazilian club Santos in 1958 and Ferenc Deak for Hungarian team Ferencvaros in 1948-49.

Malaga midfielder Duda barged into Messi to set up his second successful penalty and match Mueller. Messi surpassed the former West Germany striker when Iniesta slipped a perfect long ball between defenders.

"Barcelona tried," said Guardiola, who is stepping down to be replaced by assistant Tito Vilanova at the end of the season. "There wasn't much difference. The league is very long and he who deserves to win, wins. And Madrid was a deserved winner."

Earlier, Zaragoza beat Levante 1-0 to keep its hopes alive of avoiding relegation following Rayo Vallecano's 1-0 loss at Mallorca, which scored through Chori Castro in the 62nd minute.

Edu Oriol's 11th-minute goal proved the difference for Zaragoza, which moved within three points of Rayo with two games left.

Rayo has 40 points, Zaragoza 37 and Sporting Gijon 34. Racing Santander is already relegated and will finish last.

Also, substitute Carlos Vela's stoppage-time goal gave Real Sociedad a 1-1 draw at 10-man Atletico Madrid to all but end Atletico's hopes of qualifying for next season's Champions League.

Valencia thrashed 10-man Osasuna 4-0 to move three points ahead of Malaga and keep a firm grip on third place and an automatic Champions League qualifying place.

Levante is three points behind Malaga, which is fourth and in the final Champions League qualifying spot. Atletico trails Malaga by five points.

Real Betis came from behind to beat city rival Sevilla 2-1.