A scruffy late winner was scored by Arturo Vidal as La Liga leaders Barcelona came from behind to beat Leganes bottom.
The brilliant early strike by Youssef En-Nesyri brought Leganes ahead as Barcelona worked in response.
After the break, the champions improved and Luis Suarez scored a clinical header.
Vidal’s finish put the rivals Real Madrid, who play Real Sociedad, three points clear to the top.
The goal of the Chilean midfielder was fortuitous, the corner of Ousmane Dembele deflecting kindly from Ruben Perez and falling to Vidal, who was unable to miss out from a yard.
This season, Barcelona lost three times from home and looked nervous in the first half, deservedly falling back when En-Nesyri picked up the top corner after 11 minutes with a rasping strike.
Oscar Rodriguez was supposed to have tripled the lead of the home side, but hit the side-netting as their visitors suffered in the final third.
After half-time, Gerard Pique hit the post in the middle of Barca, but they will be pleased to have emerged with all three points from this game.