The World Player of the Year dinked in the winner in the 77th minute as Barca desperately poured forward after Andoni Iraola had cancelled out David Villa's early opener with a 49th-minute penalty.
Barca moved on to 65 points from 24 matches, keeping Real Madrid five points back in second after Jose Mourinho's outfit eased to a 2-0 victory over Levante on Saturday.
In other games, fourth-placed Villarreal's faltering form continued when they were held 1-1 at home by basement side Malaga, and Osasuna's new coach Jose Luis Mendilibar led his team to a stunning 4-0 win over sixth-placed Espanyol.
The goal of the day came from Deportivo La Coruna goalkeeper Daniel Aranzubia, who headed a last-ditch equaliser for a 1-1 draw at Almeria.
Barca's 16-match winning streak in the league ended with a 1-1 draw at Sporting last weekend and a 2-1 defeat at Arsenal in the Champions League on Wednesday suggested the Spanish champions were suffering a dip in form.
Those doubts appeared misplaced when Xavi's diagonal pass over the defence found the overlapping Dani Alves who cushioned a volley inside for Villa to fire first time into the corner after only four minutes.
For all their domination, however, they could not find a second and when Sergio Busquets brought down Fernando Llorente for a penalty, Iraola's spot kick clearly rattled the hosts.
Harried and hustled, Barca threw caution to the wind and just when it looked like the visitors were going to deny them Xavi picked out another Alves run and he crossed low for Messi to score.
Villarreal missed the chance to move above third-placed Valencia, who had drawn 0-0 with Sporting Gijón on Saturday, when they drew at the Madrigal.
Marco Ruben gave the hosts the lead in the 35th minute, bundling in from close range after good work from Giuseppe Rossi, but Sebastian Fernandez levelled on a counter-attack for Malaga eight minutes from time.
A third consecutive game without a win left Villarreal on 46 points, two behind Valencia.