Barca dominated possession for the first 25 minutes, but were stunned when Odion Ighalo put the hosts ahead at the Estadio Nuevo Los Carmenes.
Messi tapped in a deserved equaliser five minutes into the second half and then curled in a trademark free-kick 17 minutes from time to complete the turnaround and move Barca 15 points clear at the summit.
A first-half goal by Javier Saviola earned Malaga victory over Athletic Bilbao to ensure they will remain fourth in the Primera Division table by the end of the weekend.
The result was also the perfect morale-booster for the Andalusians ahead of their Champions League last-16 first-leg tie against Porto next week.
Osasuna claimed a vital 1-0 victory at home to Real Zaragoza to move above their opponents in the relegation scrap at the foot of the standings.
Kike Sola scored the only goal of the game with just four minutes on the clock when he produced a tremendous header to convert Damia's inswinging cross from the left flank.
Celta Vigo remain in the relegation zone of the Primera Division after suffering their third defeat in a row away to Getafe.
All the goals came in a frantic first half as Adrian Colunga opened the scoring for the hosts after 10 minutes but Augusto Fernandez equalised just 10 minutes later.
Diego Castro and Federico Fernandez then added goals of their own before the break.