Barca had thrown away a two-goal advantage against Deportivo but Messi, who scored their second goal, struck again in the 82nd minute to restore the lead before completing his treble.
Barcelona beat Deportivo La Coruna 4-2 with Philippe Coutinho and Lionel Messi among the goalscorers to clinch a seventh La Liga title in 10 years.
Lionel Messi scored a hat-trick as Barcelona overcame a resurgent Deportivo La Coruna side to seal their third title in four years with four games left to play in the season.
Gareth Bale and Borja Mayoral scored first-half goals as Madrid defeated Leganes 2-1 to move within a point of second-place Atletico Madrid.
Andres Iniesta, who turns 34 on May 11, decided it was time to go out on top after likely securing a domestic double.
Atletico Madrid held 0-0 at home by Real Betis in La Liga in a second straight setback before Diego Simeone's team faces Arsenal in the Europa League semifinals.
Espanyol sacked coach Quique Sanchez Flores after just under two seasons in charge, also announcing on Friday that they have parted ways with sporting director Jordi Lardin.
Barcelona, who drew 2-2 with Celta Vigo on Tuesday and are still unbeaten in the league, will clinch the title if they win their next league game away to Deportivo La Coruna on April 29.
Cristiano Ronaldo came through for Real Madrid again, this time with a backheel flick that saved his team from a loss in the Spanish league.
Barcelona held on to a 2-2 draw at Celta Vigo in the Spanish league on Tuesday despite resting its regular starters and finishing the match with 10 men.
Ernesto Valverde's Barcelona set a La Liga record by going 39 games unbeaten on Saturday as they beat Valencia, but the coach may risk losing the chance to extend it on Tuesday when his team face Celta Vigo away with other commitments looming.
Real Madrid play again in la Liga on Wednesday at home to Athletic Bilbao before their Champions League semi-final first leg against Bayern Munich on April 25.
Barcelona set a Liga record by remaining 39 games unbeaten. This win takes them another step closer to yet another title.
Barcelona coach Ernesto Valverde said his side cannot "stay at home crying" after their painful 3-0 defeat at AS Roma which dumped them out of the Champions League on away goals, urging them to focus on winning the La Liga title.
With the wounds still fresh from their shock Champions League exit, Barcelona will try to pull themselves together and resume their bid to wrap up La Liga title.
With the score poised at 1-1 in Sunday's Madrid derby in La Liga between Real and Atletico, Cristiano Ronaldo's number appeared on the fourth official's electronic board in red and the crowd in the Santiago Bernabeu fell silent.
Atletico Madrid striker Fernando Torres plans to leave the club when his contract expires at the end of the season to seek more game time.
Cristiano Ronaldo and Antoine Griezmann each scored as Atletico Madrid held Real Madrid 1-1 at Santiago Bernabeu Stadium to keep a four-point lead.
Cristiano Ronaldo and Antoine Griezmann scored within five minutes of each other as Real and Atletico ended the match with a point apiece.
Lionel Messi scored all of Barcelona's goals in their 3-1 win over Leganes which helped them equal a Spanish league record of 38 unbeaten matches.
Real Madrid host Atletico Madrid as spot for the second LaLiga place heats up. Find out all the information about when and where to watch the Madrid derby.
Atletico Madrid beat La Liga strugglers Deportivo La Coruna 1-0 at home on Sunday without starting first choice strikers Diego Costa and Antoine Griezmann.
Lionel Messi came off the bench to preserve Barcelona's unbeaten run in La Liga with a sensational late equaliser in a thrilling 2-2 draw at Sevilla.
Gareth Bale exhibited his phenomenal pace and power to race on to an exquisite through ball from Luka Modric and fire in the opening goal in the 26th minute
Barcelona must decide whether to field Lionel Messi as they resume their bid for the Liga title away to Sevilla on Saturday amid doubts about their talisman's fitness.



