Lionel Messi scored a spectacular double the same night he equalled Xavi Hernandez’s appearance record for Barcelona, the Argentinian inspiring his team to a 4-1 win over Huesca on Monday.

Messi tied Xavi’s 767 games in all competitions for Barca and marked yet another milestone with a brilliant brace, a curling effort in the first half flying in off the crossbar at Camp Nou before a late shot nestled in the corner.

“He’s the most important man in the history of Barca,” said coach Ronald Koeman. “Even better that he’s still with us.”

Antoine Griezmann had earlier followed suit with another impressive shot into the top corner before Huesca pulled one back, Rafa Mir converting a doubtful penalty on the stroke of half-time.

But Messi helped Barca pull away, sending in a cross for Oscar Mingueza to head in and then scoring his second as the Catalans moved to within four points of league leaders Atletico Madrid.

Messi’s performance had all the key elements of the 33-year-old’s genius. In a game that celebrated his longevity, he showed his class with perhaps his best goal of the season, his creativity with an assist and his consistency, by making it 13 consecutive campaigns that he has reached 20 La Liga goals.

“He’s so decisive,” said Huesca’s Mir. “They play with one man extra.”

Huesca stay bottom, four points adrift of safety, while Barcelona continue their own excellent form.

They have now managed 11 wins and a draw from their last 12 matches, putting them within sight of Atletico, who they still have to play at home in May.

Messi should break Xavi’s record on Sunday against Real Sociedad and the club toasted his achievement with a video that included tributes from numerous current and former team-mates including Gerard Pique, Sergio Busquets, Luis Suarez, Neymar, Andres Iniesta, Carlos Puyol and Xavi himself.

“You’re still breaking records,” said Suarez. “I think this one says a lot about you as a player and what you represent for Barcelona.”

“We think you’re extraordinary, something from another planet,” said Neymar.

Koeman played Frenkie de Jong again in the centre of a back three but he was replaced in the second half by Ronald Araujo, whose return from injury should also be a major boost to Barca during the run-in.

Messi rose to the occasion in the 13th minute. He darted back to receive a pass from Busquets and flicked his first touch around the sliding Jorge Pulido. The ball was still spinning when he tapped it forward and whipped a shot that flew off the crossbar and in.

Barcelona were dominant and Jordi Alba thrashed a shot against the crossbar before Griezmann made it two, played into space by Pedri and driving another thundering effort into the same corner Messi had picked out.

De Jong poked a cross onto bar and Huesca were given hope at the end of the half when a scintillating counter-attack was rewarded with a mysterious penalty, Mir failing to connect with Ferreiro’s cross but given a spot-kick anyway, seemingly for a late challenge from Marc-Andre ter Stegen. Mir made no mistake.

Yet Barca gave themselves breathing space when Mingueza headed in his first Barcelona goal from a cross by Messi, who had the last word, cutting in from the right and firing into the bottom corner for his 661st.