Messi opened the scoring in the 23rd minute from the penalty spot, only to commit the foul that would lead to Celta's equalizer - a well-placed free kick from Lucas Olaza - three minutes before the end of the second half.
The hat trick marks Messi's 34th of his La Liga career (459 games), tying Cristiano Ronaldo's record.
"It's clear that when it's so close we have the advantage of having the best player in the world and the best free-kick taker in the world", said Sergio Busquets, who scored the late fourth goal.
Ernesto Valverde's Barcelona are flawed and this win will not paper over the cracks, especially as one of which is extreme dependence on Messi. "This (taking free-kicks) is something that he has mastered to perfection".
"He is so risky, that opposition sides know they can not commit fouls around the box".
"With Leo in the team, anything is possible", Valverde was quoted as saying by Marca.
"We had a damaging defeat the other day and we needed a win tonight".
Valverde admitted the defeat at Levante created an unsettled atmosphere at Camp Nou, saying: "When you do not win, there is uncertainty surrounding your environment".
"If they do, they know Messi can punish them". He has a very high percentage of fouls, you cannot avoid making mistakes in that area.
Barcelona later confirmed right-back Nelson Semedo would be out for around five weeks with the calf problem which forced him off after 23 minutes.