Messi came close to opening the scoring himself shortly before the break as he unleashed a curling effort, but his shot went just wide.
Messi continued to pose a threat for the visitors, almost heading the ball in from an Ivan Rakitic corner before seeing a low shot blocked on the line moments later.
The hosts were denied by the post inside the final 20 minutes when Tomas Pina unleashed a powerful strike from the edge of the box.
The miss proved costly as Barcelona finally broke the deadlock in the 82nd minute when Messi slid the ball forward for Sandro to tap in from close range.
The result leaves Barcelona at the top of the table with six points from their first two games of the Spanish season.