The 26-year-old opened the scoring after 19 minutes to equal Paulino Alcantara's record of 369 goals in all competitions - including friendlies - for Barcelona. Alexis Sanchez and Andres Iniesta increased the hosts' advantage before the break.
Messi struck again in the second half to move onto 370 goals and become the club's undisputed top marksman, and then completed his treble with a simple finish in the 87th minute, after substitute Cristian Tello had rammed in the fifth goal.
There was still time for a seventh goal, however, Messi adding an assist to his goal haul by teeing up Pedro.
Barca remain third in the Primera Division and four points behind leaders Real Madrid despite the win, but will have the chance to cut the gap with their arch rivals at the Bernabeu in a week's time.
And this slick and dominant performance will give Gerardo Martino's side plenty of confidence going into the Clasico, banishing any doubts they had about their ability to win the league following last week's shock defeat at Valladolid.
Despite cruising to an emphatic victory once Messi had scored, Barca had struggled to get a hold on the game early on, and Osasuna had the ball in the net early on through Barca academy graduate Oriol Riera, but the goal was ruled offside.
The Catalans took an expected lead after a well worked move. Pedro attacked down the left and played the ball back to Xavi, who thought about shooting but instead played in Alexis, whose low cross was diverted in by the toe of Messi.
And Martino's men should have got a second goal a moment later, Iniesta finding Alexis on the right-hand side of the area but the Chilean's attempted lob went over the bar.
Alexis would not have to wait much longer before getting on the scoresheet however, appearing on the edge of the six-yard box to knock in a pass from Jordi Alba, who had combined well with Iniesta.
The Spain midfielder had been pivotal to both goals and decided he wanted one for himself, receiving the ball 30 yards out, taking two touches forward then driving the ball into the far corner.
Dani Alves wanted a piece of the action too and tried his luck from similar range, but saw his effort tipped over by Andres Fernandez. The goalkeeper then had to repel a volley from Xavi after a looping ball over the top from Iniesta.
Pedro could have added a fourth early in the second half, shooting into the side netting from an angle, but Messi got his milestone goal on 62 minutes, finishing off a fine move between the Argentinian and Iniesta.
Messi should have then got his third goal, but lifted the ball over the crossbar, so it was Tello who got the fifth of the afternoon, drilling the ball into the top corner from outside the area.
Messi then controlled a square pass from Alves and finished from close range to score his hat-trick, and then laid the ball on a plate for Pedro to complete the drubbing.