Xavi Hernandez and Argentinian striker Messi hit the net for Barcelona in the first half before Diego Mainz reduced arrears for the Andalusians on 55 minutes.
In doing so, Messi equalled the record of 232 goals held by club legend Cesar Rodriguez.
Guilherme Siqueira levelled from the spot for the away side seven minutes later after Dani Alves pulled down Dani Benitez, raising the prospect of a possible upset.
However those fears lasted only minutes as Messi produced a trademark chip over Granada's Brazilian 'keeper Julio Cesar in the 67th minute to put Barcelona 3-2 ahead with a record-setting 233rd goal for the club.
Cristian Tello then drove the ball into the net after Messi's shot was parried by Cesar to make it 4-2 for the hosts, and Messi followed up with another fine piece of individual skill to make it 5-2 and extend his record in the 86th minute.
Dani Alves received a second yellow card on 88 minutes for handling the ball in the area and Siqueira scored from the spot again, moments before the final whistle.
Cesar played in the 1940s and 1950s and died in 1995 at the age of 74.
Previously, Cesar was believed to have scored 235 goals for Barcelona, but a study had revealed that the 1950's striker had in fact scored 232 goals -- a statistic confirmed earlier on Tuesday on Barca's website.
Messi's latest hat-trick, taking his Barca total to 234, also made it 33 goals so far in the league, one more than Real Madrid striker Cristiano Ronaldo.
Barcelona's win took them to within five points of Madrid, with the league leaders playing away at Villarreal on Wednesday.