The forward twice erased deficits after Jesus Navas and Gabriel Mercado scored first-half goals.
The Blaugrana pushed for a late winner and Messi delivered on the 85th minute, bagging his 50th career hat-trick:
Luis Suarez ended his goalless run in the 93rd minute to put the final score on the board.
The win pushed Barcelona's lead to double-digit points in the standings, but Atletico Madrid still have a match in hand.
Barcelona's Defensive Issues Make Real Madrid Favourites for El Clasico
Samuel Umtiti made his first start for the Catalans since November, but if fans thought that would hand the team's defence a boost on Saturday, they were sorely mistaken.
The hosts twice took the lead in the first half, and individual mistakes proved costly on each occasion.
Navas' opener was a direct result of Messi turning the ball over in a bad position, and none of his team-mates could make up for the mistake.
To Messi's credit, he made up for the error with a stunning volley almost immediately.
The Andalusians would restore their advantage through Mercado, and this time it was Sergio Busquets who allowed his man far too much space, per The Spanish Football Podcast:
Individual errors and passive defending have become serious issues for the Catalans, who often make up for their defensive struggles with brilliant attacking play. Outscoring opposition works against smaller clubs, but rivals Real Madrid will feast on the Blaugrana, who are slumping in defence at the worst time possible.
With back-to-back Clasico matches on the schedule in the Copa del Rey and league, respectively, Real―who were on a lengthy win streak in La Liga until they lost to Girona―have to be considered favourites at this point.
Umtiti lacks match rhythm, and Barcelona's defence as a whole has too many issues to fix in a short amount of time.
Valverde Must Drop Suarez for Dembele in Copa Clasico
Suarez had another poor outing against Sevilla, continuing a slump that started back in January.
Although he ended his scoring drought in the closing minutes, fans will likely be disappointed by his overall performance.
Prior to Saturday, the 32-year-old's last goal came in the Copa del Rey against Sevilla, and he had gone five matches without finding the net.
Ahead of Saturday's contest, manager Ernesto Valverde backed the former Liverpool man:
Calls to drop him will only become stronger ahead of Wednesday's Clasico. In Andalusia, Suarez looked passive, ruining several promising attacking moves by losing the ball or being caught out of position. He did set up two good chances with his passing, but until the last-minute goal, the good could not outweigh the bad.
Half-time substitute Ousmane Dembele was far more lively, and while he too made mistakes, his energy proved vital. He recorded an assist for Messi's second goal, and that should give Valverde plenty to think about for the match against Real.
Messi has found plenty of success in a central role this season, and he should return to the false-nine role against Los Blancos, with Dembele and Philippe Coutinho flanking him. Suarez could do with some time on the bench, and he could be used as a super-sub against Real.
Shaking things up a bit may be just what the veteran forward needs, while Dembele deserves another start on the back of his stellar play.
Barcelona will visit Real Madrid for the return leg of the Copa del Rey on Wednesday. On March 3, the two giants meet again at the Estadio Santiago Bernabeu in La Liga.
Sevilla's next match will also be on March 3, against Huesca.