He scored two excellent finishes from outside the box before smashing in a third off the underside of the crossbar.
Antoine Griezmann had opened the scoring for Barca, with Luis Suarez netting an outrageous backheel.
Messi showed off his Ballon d’Or trophy – awarded to the best player in the world – to the Nou Camp crowd before kick-off, with his family on the pitch alongside him.
And he finished the match with his 35th La Liga hat-trick, breaking the record of Cristiano Ronaldo.
Barcelona were excellent at times, particularly in the first half, with some fantastic passing movement.
However their first goal came when Griezmann chased onto Marc-Andre ter Stegen’s long goal-kick before clipping the ball over the goalkeeper.
The France international then set up Messi’s first, a fine curling effort from 25 yards. Budimir scored a deflected strike for Mallorca, before Messi scored a similar goal to his first, this time from an Ivan Rakitic pass.
Suarez scored the best goal of the game, however. An excellent passing move ended with Frenkie de Jong finding Suarez, who backheeled the ball into the ground and over goalkeeper Manolo Reina.