After a tense first half in which both teams had chances, Barcelona took the lead after halftime when Raphinha’s cross for Robert Lewandowski was unintentionally deflected into the net by Leganes defender Jorge Saenz.
This was the decisive goal, and Lewandowski, chasing his 100th goal for the Catalans, later saw his header from Raphinha’s cross go wide before he was replaced by Ferran Torres after 67 minutes.
Barcelona’s victory at Leganes on Saturday increased their lead at the top to seven points, and their unbeaten La Liga run to 13 games.
Dani Raba’s header of Adria Altimira’s cross appeared to have given the home team the equaliser, but the goal was disallowed for offside.
Real Madrid, who are in second place with 63 points and will visit Alaves on Sunday, is now 70 points ahead of Hansi Flick’s team.
With 28 points, Leganes are still two points outside the safety zone and in second-bottom place.