Match ends, Barcelona 2, Leganés 1.
Lionel Messi's 90th-minute penalty saw off the challenge of gutsy Leganes and spared Barcelona from a second successive embarrassing result.
The champions underwhelmed again after Tuesday's 4-0 Champions League defeat at Paris St-Germain and had keeper Marc-Andre ter Stegen to thank for a string of great saves.
Messi gave Barca an early lead, before Unai Lopez fired in the equaliser.
The Barcelona forward then slammed in the late winner from the spot.
Victory sees the Catalan giants move two points above Sevilla into second place in La Liga. They have 51 points, one fewer than leaders Real Madrid who have two games in hand.
Ter Stegen saves Barca from humiliation
Luis Enrique's side threatened an avalanche of goals after Luis Suarez teed up Messi with an inch-perfect low cross for the opener in the third minute.
It was the Argentine forward's first contact with the ball in the area having failed to register a single touch in the box against PSG on Tuesday.
However, the glut of goals never materialised and the attacking threats of Messi, Suarez and Neymar struggled to break down the disciplined defence of the league's 17th-placed side.
Leganes - promoted to the top flight this season for the first time in their 89-year history - markedly grew in confidence and began to attack a Barca backline without stalwarts Gerard Pique and Jordi Alba.
Winger Nabil El Zhar was twice thwarted by Ter Stegen. Both shots produced diving saves from the German, the second more impressive after the Moroccan's strike took a deflection.
And the former Borussia Monchengladbach keeper made another great save, this time with his foot, to deny Miguel Angel Guerrero.
Messi winner follows Leganes controversy
Had Barcelona lost, coach Enrique would have had a case regarding Leganes' dubious 71st-minute equaliser.
Barca full-back Sergi Roberto had possession of the ball but appeared to be hauled back by Miguel Angel Guerrero, who fed Darwin Machis to deliver a cross for Lopez to slot in.
However, with two minutes of the allotted 90 remaining, Neymar cut in from the left and was brought down by Martin Mantovani.
Referee Ignacio Iglesias Villanueva pointed to the spot and Messi stepped up to convert, to the relief of the Barca fans and coach Enrique.
Line-ups
Barcelona
Formation 4-3-3
- 1ter Stegen
- 20Roberto
- 23Umtiti
- 24Mathieu
- 19DigneSubstituted forAlbaat 81'minutes
- 4Rakitic
- 21André GomesSubstituted forIniestaat 80'minutes
- 12RafinhaSubstituted forD Suárezat 80'minutes
- 10Messi
- 9SuárezBooked at 46mins
- 11Neymar
Substitutes
- 3Piqué
- 6D Suárez
- 8Iniesta
- 13Cillessen
- 17Alcácer
- 18Alba
- 28Aleñá
Leganés
Formation 4-5-1
- 13Herrerín
- 2Román Triguero
- 5MantovaniBooked at 55mins
- 22SiovasBooked at 87minsSubstituted forInsúaat 87'minutes
- 15Rico
- 25El Zhar
- 6Martín-Romo García-AdamezBooked at 90mins
- 12MoránSubstituted forLópezat 65'minutes
- 8Pires
- 11SzymanowskiSubstituted forMachísat 70'minutes
- 9Guerrero
Substitutes
- 1Champagne
- 7Machís
- 10Bueno
- 17Díaz
- 18Insúa
- 19López
- 20Neves
- Referee:
- Ignacio Iglesias Villanueva
- Attendance:
- 63,378
Match Stats
- Possession
- Home72%
- Away28%
- Shots
- Home13
- Away11
- Shots on Target
- Home6
- Away6
- Corners
- Home4
- Away4
- Fouls
- Home8
- Away18
Live Text
Post update
Full Time
Second Half ends, Barcelona 2, Leganés 1.
Booking
Alberto (Leganés) is shown the yellow card for a bad foul.
Post update
Neymar (Barcelona) wins a free kick in the defensive half.
Post update
Foul by Alberto (Leganés).
Post update
Luis Suárez (Barcelona) wins a free kick on the left wing.
Post update
Foul by Martín Mantovani (Leganés).
Post update
Attempt missed. Nabil El Zhar (Leganés) right footed shot from outside the box is close, but misses to the left following a corner.
Post update
Corner, Leganés. Conceded by Denis Suárez.
Post update
Foul by Neymar (Barcelona).
Post update
Nabil El Zhar (Leganés) wins a free kick on the right wing.
Goal!
Goal! Barcelona 2, Leganés 1. Lionel Messi (Barcelona) converts the penalty with a left footed shot to the bottom left corner.
Post update
Penalty Barcelona. Neymar draws a foul in the penalty area.
Post update
Penalty conceded by Martín Mantovani (Leganés) after a foul in the penalty area.
Substitution
Substitution, Leganés. Pablo Insúa replaces Dimitrios Siovas.
Booking
Dimitrios Siovas (Leganés) is shown the yellow card.
Post update
Delay over. They are ready to continue.
Post update
Delay in match Iago Herrerín (Leganés) because of an injury.
Post update
Corner, Barcelona. Conceded by Tito.
Post update
Attempt saved. Gabriel Pires (Leganés) with an attempt from the centre of the box is saved in the bottom left corner. Assisted by Unai López with a cross.