Messi’s sixth free kick of the season gave Barca the lead, and while former Liverpool man Nabil El Zhar pulled one back for Lega, the No 10 scored two more to ensure the Catalans equalled La Liga’s record unbeaten run of 38 games.
Barca brought in Thomas Vermaelen and Andre Gomes, while Philippe Coutinho returned on the left wing after he was ineligible for Wednesday’s 4-1 victory over Roma in the Champions League quarter-finals.
The Blaugrana had won all of their three previous meetings with Leganes, whose last away victory came in October.
Barca had their eyes on Real Sociedad’s 38-year-old record, and their dominant start was made to count by Messi, who curled a free kick into Ivan Cuellar’s bottom-right corner.
Five minutes later, Messi doubled his and the hosts’ lead, running on to Philippe Coutinho’s through ball, before coolly slotting home.
Lega were much improved after the restart and deservedly pulled a goal back, when El Zhar slipped as he fired a shot into Marc-Andre ter Stegen’s bottom left.
Luis Suarez should’ve netted Barca’s third long before, but his finish from a yard out was pushed away by Cuellar, while he slid a cross over, despite being faced with an open goal.
It was left to Messi to kill off Los Pepineros, and that he did with only three minutes to spare, the No 10 meeting Ousmane Dembele’s low cross and hooking past Cuellar from close range.