Paris Saint-Germain thumped Barca 4-0 in their last-16, first-leg tie on Tuesday to heap the pressure on coach Luis Enrique, and while Messi’s late winner prevented a second embarrassing result in six days, the Catalans failed to produce the commanding response that many expected.

Early on Barca looked every inch a side desperate to respond emphatically to that humbling result in Paris and it was hardly surprising to see Messi put them ahead after just four minutes at Camp Nou.

But the hosts fluttered between attacking vibrancy and wastefulness throughout the first period, while Leganes were also afforded several good chances, perhaps more than they would have expected.

Barca did not produce an improvement after the break and few would have suggested spirited Leganes did not deserve a share of the spoils, with a Ter Stegen error allowing Unai Lopez to level 19 minutes from the end.

But Neymar won a penalty in the 90th minute and Messi coolly slotted it home to salvage the win which keeps Barca second in LaLiga, though Luis Enrique will undoubtedly have more questions to answer after another poor display.

Barca’s purpose was clear during the early exchanges and they swiftly established control, breaking Leganes’ resolve early on.

Luis Suarez was released down the left flank by Neymar and delivered an inch-perfect cross with the outside of his right foot for Messi to tap in from close range.

Barca were almost punished on the break in the 18th minute, though, as Nabil El Zhar was thwarted when one-on-one with Ter Stegen, before forcing the German into a fine save down to his left at the second attempt.

That let-off appeared to jolt Barca back into life and Messi almost doubled his tally shortly after, racing on to Suarez’s throughball into the right side of the area only to see his flicked effort kept out by Iago Herrerin.

But Ter Stegen had to be at his best again just before the break to keep Barca’s lead intact, reacting well to El Zhar’s deflected effort.

Barca looked no sturdier at the back after the break and had to rely on Ter Stegen for a third time, as Miguel Angel Guerrero burst into the left side of the box and got a powerful shot away from a tight angle.

The hosts eventually crafted their first opportunity of the second period, though Neymar’s effort was well saved by the right leg of Herrerin after he cut in from the left.

Leganes took full advantage and Ter Stegen’s previous efforts were undone in the 71st minute.

Sergi Roberto was robbed in a compromising position and Darwin Machis showed great awareness to pick out Lopez on the edge of the box, with his controlled effort slipping under the out-stretched right leg of Ter Stegen.

Barca ultimately rescued themselves soon after Andres Iniesta’s entrance in the 80th minute, as the Spaniard became only the second player to reach 400 league appearances for Barca.

Neymar was felled in the area by Martin Mantovani and the referee showed no hesitation in pointing to the spot, from where Messi converted to spare Barca, though his lack of celebration highlighted that the overwhelming feeling was one of relief.