Messi went into the match needing a goal to break Pele's mark for most with a single club and went close twice in the opening 20 minutes before setting up Clement Lenglet for a header to give Barcelona a first-half lead.
Barcelona doubled their lead in the 35th minute with Messi once again pulling the strings, playing Sergino Dest into the area to cross for Martin Braithwaite, who stretched out and poked home from close range to give the visitors a 2-0 break at the half.
Messi's record goal for Barcelona came midway through the second half when Pedri's cheeky flick gave his teammate clear sight of the goal and the Argentine made no mistake about his finish past Jordi Masip.
"Today was a very complete performance. We needed to win this game and we did that while showing some real quality," said Barca scorer Lenglet.
"Today our tactics worked well and we're very happy. Our full-backs were able to play high up the pitch and it was a consistent performance overall, while we didn't let our opponents have too many chances."
The result sees Barcelona move into fifth in La Liga, but they remain eight points behind leaders Atletico Madrid, who also have a game in hand.
Ronald Koeman credited a formation switch for his team's comprehensive showing, with both Antoine Griezmann and Philippe Coutinho left on the bench.
"For this game we changed our formation to give us more security at the back and make the most of the quality of our full-backs," Koeman explained after the victory, Barca's first away league win since Oct. 1.
"At the same time, we were able to build plays without any problems and have lots of possession and players running between the lines. We saw a team that meant business, that showed good concentration and we created a lot of opportunities."