Barcelona lost for the first time this season after bottom-of-the-table Leganes came from behind to pull off a sensational victory.
Philippe Coutinho had put Barca in front with a 20-yard volley but Nabil el Zhar and Oscar Rodriguez scored twice in just 68 seconds.
Barca boss Ernesto Valverde lost for just the second time in La Liga since taking charge in the summer of 2017.
Leganes had just one point from five games going into the match.
But they stunned their illustrious opponents after the break, with Gerard Pique at fault for their second goal.
The defender inadvertently passed to Oscar, who is on loan from Real Madrid and slotted home the winner from 12 yards.
Barcelona will lose their lead at the top of the table if Real Madrid avoid defeat against Sevilla, with that match taking place later on Wednesday.