Lionel Messi's late penalty spared Barcelona further embarrassment as they bounced back from their Champions League humiliation by beating struggling Leganes 2-1 in La Liga.
Barca were thrashed 4-0 by Paris Saint-Germain on Tuesday and almost fell victim to another shock as Leganes looked on course to snatch an unlikely draw at the Nou Camp.
Messi, however, held his nerve to convert an 89th-minute penalty, which moves Barca to within one point of Real Madrid at the top of the table. However, Madrid have two games in hand.
It was Messi's second goal of the game after he had given the Catalans an early lead but Unai Lopez stunned the favourites with a 71st-minute equaliser before the Argentinian's late heroics.
The performance will do little to ease the pressure on under-fire Barcelona boss Luis Enrique, who made four changes from the side hammered at the Parc des Princes.
Andres Iniesta, Jordi Alba and Gerard Pique were all dropped to the bench while the suspended Sergio Busquets also missed out.
It meant starts for Lucas Digne and Jeremy Mathieu in defence, as well as Ivan Rakitic and Rafinha, who came into midfield.
Messi was one of the most disappointing players in midweek but the striker needed only four minutes to score his 32nd goal of the season, finishing off Luis Suarez's curled pass from close range.
Leganes could have equalised when Nabil El Zhar nipped in behind but Marc-Andre ter Stegen saved his poked finish and then palmed away his bending effort on the rebound to keep Barcelona's lead intact.
Despite their advanatage, the home side were struggling for fluency and the crowd groaned when Samuel Umtiti's attempted pass to Sergi Roberto flew straight out of play.
Messi almost scored a second after a neat one-two with Suarez but his angled finish was saved and he also curled a free kick straight into the wall after being fouled on the edge of the penalty area.
Leganes were creating chances of their own, however, as Martin Mantovani headed over when he should have hit the target and El Zhar drew a strong save from Ter Stegen when his dipping volley took a mean deflection.
The chances created belief and Leganes continued where they left off in the second half as Ter Stegen was again called into action to keep out Miguel Angel Guerrero's left-footed shot.
Barca were fortunate to escape a red card when Mathieu appeared to block off Guerrero as he honed in on goal and the striker was involved again soon after as Leganes finally equalised.
After nicking the ball off Roberto, Guerrero drove into the penalty area and cut back for substitute Lopez to finish.
Iniesta and Alba both came off the bench with 10 minutes remaining but it was Leganes who could have pulled ahead when Gabriel peeled free, but his chested finish allowed a comfortable save.
It was a moment they would live to regret as, with two minutes left, Mantovani fouled Neymar in the box and Messi showed nerves of steel, smashing the penalty into the top corner.
There was still time for one last chance, El Zhar's stinging half-volley nicking the post, but Barcelona held on for a much-needed, albeit unconvincing, victory.