Athletic had a five-man wall, a player lying behind the wall and another on the line but Messi still managed to curl the ball into the top corner – his 49th free-kick goal for the club.
Athletic were level when Jordi Alba turned a cross into his own net.
But Antoine Griezmann slammed in the winner from Oscar Mingueza’s pass.
Barcelona move above Real Madrid on goal difference, but the rivals both sit 10 points behind Atletico Madrid – who have a game in hand on both sides and who defeated Cadiz earlier in the day.
Ronald Koeman’s side seem to be over their dreadful start to the season with eight wins and two draws in their past 10 La Liga games.
Barcelona’s day ended better than it started, with the club denying leaking details of Messi’s contract to El Mundo.
The club plan legal action after the Spanish newspaper published details of his £492m contract. (Courtesy BBC)