Lionel Messi scored a hat-trick to become Barcelona's all-time top scorer as the Catalans strolled to a 7-0 victory over Osasuna that put them four points off the top of La Liga.

The Argentine now has 371 goals for Barca in all matches including friendlies, beating the record of Paulino Alcantara, who played for the club between 1912 and 1927, and notched up 369 goals.

Messi struck the opener after 18 minutes in a morale-boosting victory for the Catalan side ahead of next week's El Clasico at the Bernabeu.

Barca knocked Manchester City out of the Champions League last Wednesday but went into the Osasuna clash on the back of two defeats from their past three league games.

Alexis Sanchez pounced to double the lead after 22 minutes and Andres Iniesta hit a fine left-footed drive from 20 yards with little over half an hour gone.

Messi bagged another with a shot into the roof of the net from close range just after the hour before substitute Cristian Tello netted with a powerful strike. Messi scored his third late on and then he set-up Pedro to complete the rout in stoppage time.

"As long as the people want me here I will stay here. My intention is to retire with the Barcelona shirt," Messi told reporters.

Looking ahead to the Clasico, he added: "Hopefully we can play a good game. We know it will be difficult but we will do our best to fight for the league until the end."

Brazilian Neymar was a surprise absentee from the starting lineup in a win that left Barca on 66 points from 28 matches, four behind Real and one behind Atletico Madrid who beat Espanyol 1-0 on Saturday.

There were some anxious fans in the crowd after their recent poor run but Messi calmed the nerves with the opening goal from a well-worked passing move. Xavi found Sanchez who rolled the ball across the area and Messi steered home.

The Chilean Sanchez continued his good form with his 17th goal of the season, slotting a left-wing cross from Jordi Alba.

Barca were stroking the ball around with confidence when Iniesta found his range with a shot from outside the area which found the corner.

Messi combined with Iniesta to get another midway through the second half before Tello, who came on a minute earlier, cracked in a 25-yard effort. With Osasuna in disarray, Messi and Pedro hit two more.