Perhaps thinking of their Champions League tie in Rome in midweek the Barca players seemed to take their foot off the gas and Nabil El Zhar gave Leganes hope in the 68th minute.
Valverde decided against resting his star player for the LaLiga clash with Leganes on Saturday - and watched on as the club's all-time leading scorer bagged a treble.
Reuters Sport looks at five reasons why Ernesto Valverde's side have proved invincible this season in Spain. Left back Jordi Alba has undergone the most dramatic transformation under Valverde after falling out of favour under Luis Enrique, and has developed a particularly profitable understanding with Messi.
Sergi Roberto at Left-Back?
After being picked out by Philippe Coutinho, Messi then doubled the score-line, holding off two defenders before finding the net with a trademark finish, which he nearly passed into the goal. Barcelona is now at the top of the La Liga table and should be crowned champions in a few weeks. He secured the three points after 87 minutes, controlling a pass from Dembele and dinking it past the goalkeeper.
Barcelona needed an injury time victor to beat Leganes 2-1 at home last term and dabblebet price them at 2/15 (1.13) to record another win.
Barcelona remain unbeaten in La Liga this season, which is a remarkable achievement after 31 games.
Valverde named a strong side despite having a Champions League quarter-final, second leg on Tuesday at Roma, with Messi, Luis Suarez and Philippe Coutinho all starting.
For extra motivation, the Blaugrana can reach 38 games without loss if they avoid defeat here - a run that would match Real Sociedad's national record from 1979/80.
Leganes nearly threw a spanner in the works early in the second half when El Zhar's cross from the right met by Claudio Beauvue's powerful header, which only just cleared Marc-Andre ter Stegen's crossbar.