Bottom-placed Leganes shocked Barcelona 2-1 in the La Liga on Wednesday, handing the defending champions their second straight setback.
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 Real Madrid star on loan at the modest club, took advantage of Pique’s uncharacteristic mistake to score the 52nd-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.
The hosts 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.
Real, meanwhile, failed to capitalise on Barca’s defeat, losing 3-0 at Sevilla.
Andres Silva netted a brace, while Wissam Ben Yadder grabbed the third to complete the rout.
Barca and Real, though, remain tied at the top with 13 points.