Lionel Messi came off the bench to inspire Barcelona to a 3-1 victory over plucky Leganes at the Nou Camp.

Ousmane Dembele’s opener was cancelled out by on-loan Middlesbrough forward Martin Braithwaite as Leganes threatened to follow up their win over the Catalan giants in the reverse fixture earlier in the season with another shock result.

But Messi’s introduction just after the hour mark led to order being restored, with Luis Suarez converting on the rebound after an initial shot from the Barcelona captain was saved.

Messi then made sure there was no way back for the visitors in stoppage time as Barca maintained their five-point gap they had atop LaLiga heading into this weekend.

Leganes remain two points above the drop zone but they gave a decent account of themselves against a Barcelona side that also left Ivan Rakitic and Arturo Vidal out of their starting line-up, both of whom joined Messi on the substitutes’ bench.

As anticipated, the visitors were compact in defence in the early stages, allowing Barcelona very little time on the ball in the final third.

Dembele’s pace down Barcelona’s left flank was giving Leganes cause for concern and it was the 21-year-old’s trickery that allowed him to tee up Coutinho, who was unable to test Ivan Cuellar as he blazed over.

The Leganes goalkeeper made a routine save from Luis Suarez but could do nothing from stopping Dembele opening the scoring after 32 minutes.

The Frenchman dribbled infield from the right and exchanged passes with Jordi Alba before, having ghosted into the area, opening up his body and side-footing beyond Cuellar with a low first-time effort that went in off the post.

Suarez thought he should have been awarded a penalty just before half-time after going down under Cuellar’s challenge but Ricardo De Burgos Bengoetxea waved play-on and the video assistant referee backed up his decision.

The crowd were baying for Messi’s introduction as he warmed up on the touchline at the beginning of the second half and those calls grew louder when Leganes levelled in the 57th minute.

Braithwaite got the final touch, diving in to convert Youssef En-Nesyri’s ball across the area following a fluid counter-attack from the visitors, in the same week he scored the winner against Real Madrid in the Copa del Rey.

Messi and Rakitic were introduced seven minutes later and, perhaps inevitably, it was the Argentinian’s presence that led to Ernesto Valverde’s side retaking the lead.

Messi’s venomous strike from outside the area was kept out by Cuellar but only so far as Suarez, who reacted quickest to poke into the net.

The Uruguayan’s knee had also made contact with Cuellar’s face but the goal stood after several replays of the incident.

Messi got on to the score sheet in the second minute of time added-on, collecting the ball from Alba before rifling a right-footed effort into the roof of the net.