MADRID — Last-place Leganes stunned Barcelona with a 2-1 win in the Spanish league on Wednesday, handing the defending champions their second straight setback.

The result gives Real Madrid a chance to take over the league lead with a draw at Sevilla later Wednesday.

Barcelona's Philippe Coutinho opened the scoring early, but the host rallied with goals two minutes apart in the second half to earn its first win in six league games this season.

Leganes' winner came thanks to a blunder by veteran central defender Gerard Pique, who misplayed a shot while trying to clear the ball from inside the area. Oscar Rodriguez, a former member of Real Madrid's youth teams who is on loan with Leganes, took advantage of Pique's uncharacteristic mistake to score the52nd-minute winner.

It came just after Nabil El Zhar had equalized with a header from close range after a long ball into the Barcelona area.

Leganes goalkeeper Ivan Cuellar made a series of great saves near the end to preserve the victory.

Leganes had never earned a point against Barcelona in its three seasons in the first division. The club from outside Madrid had won only one point from its first five games and was coming off three straight losses.

Barcelona was coming off a home draw against Girona in the previous round.

Lionel Messi couldn't add to his 595 goals in his 700th appearance with Barcelona, including 55 non-official games.

___

More AP soccer: https://apnews.com/tag/apf-Soccer and https://twitter.com/AP_Sports

___

Tales Azzoni on Twitter: http://twitter.com/tazzoni