BARCELONA, Spain (AP) -- With its world-class attack falling short against the worst team in the Spanish league, Barcelona turned to an underused weapon to remain atop the standings.
Barcelona ground out a 2-1 victory at last-placed Leganes on Saturday thanks to a pair of second-half goals by Luis Suarez and Arturo Vidal - both from set-pieces.
Barcelona is known for its attractive passing-based attack and finely crafted buildups that can generate spectacular goals. But Leganes deployed two lines of well-coordinated defenders in front of its area and stifled almost all attempts by Barcelona to break through.
The defending champions eked out the goals - from a free kick and a corner that led to a defensive error - to ensure they stayed ahead of Real Madrid on goal difference.
''There were so many players in the middle of the field that we had to look to set-pieces,'' Barcelona coach Ernesto Valverde said. ''Today we clearly saw that we were going to need to score on a cross or an isolated play because linking up through the middle was impossible.''
Second-placed Madrid overcame a gaffe by Sergio Ramos that cost a goal to beat Real Sociedad 3-1.
Atletico Madrid was held at Granada to 1-1 before its trip to Juventus in the Champions League on Tuesday. Atletico is in third place at three points off the pace.
BOOS FOR BALE
Gareth Bale was jeered by the Santiago Bernabeu Stadium crowd when he went on as a late substitute, as Madrid's fans expressed their anger after Bale's jibe at the club while helping Wales qualify for the European Championship this week.
The images of Bale dancing and laughing behind a banner in Cardiff on Tuesday that read ''Wales. Golf. Madrid. In That Order'' were not well received in the Spanish capital.
Bale was booed every time he touched the ball, including before his cross was headed down by Karim Benzema for Luka Modric to put the result beyond doubt in the 74th.
''We need our fans behind us for 90 minutes, as well as Gareth,'' coach Zinedine Zidane said in defense of his questioned star.
Sociedad striker Willian Jose poached a poor back pass by Ramos and put it into the empty net two minutes after kickoff.
Madrid weathered a vibrant first half hour by Sociedad before Benzema chested in a corner kick from Modric to level in the 37th.
Federico Valverde's deflected shot put Madrid ahead at the start of the second half that was a riveting exchange of attacking waves by both sides.
With his preferred weaving routes through the defense cut off, Lionel Messi earned a foul outside the area. He then lobbed a free kick to Suarez, who headed home to equalize in the 53rd minute.
That canceled out a 12th-minute opener from long range by Youssef En-Nesyri.
Leganes was still close to taking a point until midfielder Ruben Perez knocked a Barcelona corner toward his own net, allowing substitute Vidal to tap in the winner with 11 minutes left.
''It hurts because they got us on set-pieces,'' said Leganes coach Javier Aguirre after his second game in charge of the small Madrid-based side. ''That is completely my fault. I have to tell my players how I want them to defend set-pieces better.''
Atletico squandered the first goal by left back Renan Lodi in the 60th when he shot between the legs of goalie Rui Silva. German Sanchez headed in Granada's response seven minutes later.
Joao Felix returned from injury for Atletico as a late substitute after missing six matches because of an ankle sprain.
Sergio Canales curled in a free kick from a tight angle on the last kick of the match to snatch a 2-1 win for Real Betis over Valencia.
Valencia's Lee Kang-in struck the woodwork in injury time before Canales got the winner.
The slip by Valencia came four days before it hosts Chelsea in the Champions League.
More AP soccer https://apnews.com/Soccer and https://twitter.com/AP-Sports