With a comparatively small crowd of an estimated 42,000 at Camp Nou, the two sides produced an entertaining encounter and although Aritz Aduriz put the visitors ahead, Barca ultimately produced the goods when they needed to.
Aduriz broke the deadlock five minutes after the break and Barca looked set to be frustrated for the match's entirety, but they eventually fought back in the final 20 minutes.
Pedro equalised with 18 minutes to go and Messi found the crucial goal two minutes later from a free-kick, which opposing goalkeeper Gorka Iraizoz - who was otherwise impressive - should have done better with.
The win moves Barcelona back to within four points of leaders Atletico Madrid and ended a run of three successive defeats in all competitions, while Athletic's lead ahead of Sevilla in fourth was cut to just three points.
Gerardo Martino acknowledged in the build-up that his debut season in Europe has not been satisfying after the club's UEFA Champions League and Copa del Rey challenges dissolved within the space of a week.
Things threatened to get even worse for Martino and Barca in the 11th minute, but Jose Manuel Pinto palmed Aduriz's shot around the post after Alex Song squandered possession in midfield.
That let-off seemed to spark Barca into life and Pedro went close four minutes later, but he could only hit a tame effort straight at Iraizoz following Messi's throughball with the Argentina star seeing a goal chalked off for offside shortly after.
They were lucky to stay level in the 31st minute, however.
The in-form Aduriz saw a spectacular overhead kick come back off the crossbar, before Pinto smartly parried away Markel Susaeta's effort from the rebound.
Barca responded by hitting the bar themselves almost immediately after as Alexis Sanchez skewed a close-range effort on to the goal frame following Adriano's low cross.
Iraizoz was kept busy until the break, but parity remained and Athletic capitalised early on in the second period.
The unconvincing Marc Bartra surrendered possession to Aduriz on the edge of the area and the Spaniard coolly slotted a precise shot into the bottom-right corner for his 16th Liga goal of the season.
Barca finally drew level in the 72nd minute as Pedro quickly shifted his feet to divert Sanchez’s wayward effort past Iraizoz and they took the lead just a few moments later.
Messi finally found his shooting boots from a free-kick, placing an effort through the poorly-formed wall and Iraizoz inexcusably let it fly under him.
Messi and substitute Cristian Tello went close to adding a third late on, and Mikel Rico saw a last-gasp shot blocked away for the visitors.
Despite a late flurry, the champions held on to their slender win to close the gap on Atletico, while Athletic’s grip of the final Champions League place slipped ahead of next week’s showdown with Sevilla.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.