Antoine Griezmann opened the scoring by netting against his old club in the 36th minute and right back Sergino Dest stretched Barca's lead shortly before halftime after latching on to a sweeping pass from Messi.
Dest struck again early in the second half before Messi controlled a sumptuous pass from Sergio Busquets and scored to mark a night in which he overtook Xavi Hernandez as Barca's record appearance maker, moving on to 768 games with the club.
Messi, however, had the final say, finishing off a flowing team move in the 89th minute to score his 23rd league goal of the season, increasing his lead at the top of the scoring charts.
The victory took Barca above Real Madrid into second place in the standings on 62 points, four behind leaders Atletico Madrid with 10 games left to play.