MADRID (AP) — Fittingly, it was a hat trick by Lionel Messi that helped Barcelona secure its 25th Spanish league title.

The playmaker has always been key for Barcelona, but this time he took it to another level by taking on even more responsibility after the departure of Neymar to Paris Saint-Germain.

"I'm very happy to have won this title," Messi said. "We know how difficult it is to win the league. We have to celebrate it."

More than ever, Messi was the team's commander on the field, dominant both as a playmaker and as a goal scorer.

He gained more freedom after Neymar left as coach Ernesto Valverde switched from a 4-3-3 formation to a 4-4-2, adding an extra midfielder. The move allowed Messi to float across the attack and the midfield more freely and made him even more dangerous.

With his hat trick in the 4-2 win at Deportivo La Coruna on Sunday, Messi reached 32 goals in the league, eight more than Real Madrid rival Cristiano Ronaldo, his closest contender in the race for top scorer. With four matches left for Barcelona, he has nine more goals than teammate Luis Suarez.

It was the ninth league title for Messi, allowing him to surpass the record he shared with Xavi Hernandez. Andres Iniesta, who last week announced he will not return for a 17th season with Barcelona, also has nine titles.

"It was a very special league for everyone because we didn't lose any matches," Messi said. "We went through difficult times but we overcame it all without losing any matches and that's incredible."

Barcelona remains unbeaten after 34 matches and will try to become the first team to go the entire season without a loss in the competition's current format.

Messi helped Barcelona keep the unbeaten streak alive by coming off the bench at Sevilla and scoring an 89th-minute goal that allowed the Catalan club to salvage a 2-2 draw. He had already scored in a dominant 3-0 performance by Barcelona at Santiago Bernabeu Stadium to virtually end Real Madrid's title defense in December.

The three goals on Sunday allowed Messi to take the lead in the Golden Boot race, surpassing the 31 goals scored by Liverpool forward Mohamed Salah in the Premier League.

Messi was particularly lethal from set pieces this season, scoring seven times from free kicks, including in a decisive 1-0 win against Atletico Madrid that halted their run for the lead in a crucial moment of the season.

Messi's low point came in Barcelona's elimination by Roma in the Champions League quarterfinals after it had won the first leg at home 4-1. Messi was far from his best in the 3-0 loss in Italy.