John Guidetti had Alaves heading towards a famous win at Camp Nou before Luis Suarez and Lionel Messi brought them crashing back to reality.

Lionel Messi assumed the familiar role of hero as Barcelona averted a Camp Nou scare to beat struggling Alaves 2-1 in LaLiga.

Atletico Madrid’s 3-0 win over Las Palmas earlier on Sunday placed a modicum of pressure on Ernesto Valverde’s runaway leaders and it seemed to weigh upon them in a ragged first-half showing.

Philippe Coutinho made his full debut, but it was a more unheralded January signing, Alaves’ Celta Vigo loanee John Guidetti, who threatened the upset with a fortuitous 23rd-minute opener.

Abelardo Fernandez’s side remain two points above the drop zone and were left to rue missed chances by the time Luis Suarez netted for the eighth top-flight match in succession with 18 minutes to play.

Typically, it fell to Messi to apply the coup de grace as he curled a delightful free-kick home in the 84th minute to spark raucous celebrations.

Barcelona remain undefeated and 11 points clear on their apparent procession to LaLiga glory.

Coutinho was lively in the opening stages but looked on as Barca’s old guard fashioned an opening in the 15th minute – Messi dropping deep and exchanging slick passes with Andres Iniesta and Suarez before forcing a clearance behind.

Alaves sprung forward from the corner and Marc-Andre ter Stegen was out sharply to deny Ibai Gomez. It was a warning Barca did not heed.

Fernando Pacheco saved low down from Suarez a few moments before Alaves streamed into a vacant Barcelona half on the counter-attack.

Guidetti bore down on Ter Stegen and enjoyed a touch of fortune as he lost his footing and kicked the ball against his other boot, the result leaving the Germany goalkeeper with no chance.

Ter Stegen arched his back to brilliantly keep out a header from Ruben Sobrino, who then ran out of steam having dribbled from halfway into the Barca box to get a shot away.

Coutinho almost found a response when his 32nd-minute effort was deflected wide, while Messi saw an angled free-kick pushed over before Pacheco tipped his next dead-ball attempt against the post to preserve Alaves’ unlikely advantage at the interval.

Seven minutes into the second half, Valverde opted to replace his full-backs, with Jordi Alba and Sergio Roberto on in place of the largely ineffective Lucas Digne and Nelson Semedo.

Their introduction added another dimension to Barca’s attacking play, but Messi was crowded out when he looked to convert Alba’s cutback from the byline.

Ibai should have given Valverde’s men a mountain to climb after the hour when he broke through on goal, only to cut back on himself and play in full-back Ruben Duarte, whose rasping shot was deflected behind by Gerard Pique.

Paco Alcacer replaced Coutinho in the hosts’ final change and Pacheco judged his angles perfectly in the 68th minute, standing up to thwart Suarez after Messi threaded a delightful pass through Duarte’s legs.

Paulinho was unable to bundle in when a roaming Pique caused havoc in the Alaves box, but the pressure eventually told.

Iniesta rolled back the years, embarking on a jinking run before sending a searching cross to the back post, where Suarez’s volley took a pair of deflections to spin beyond a helpless Pacheco.

Mubarak Wakaso clattered into Alcacer on the edge of the box, leaving a sense of inevitability when Messi stood over the consequent set-piece six minutes from time, though that did not make his decisive strike any less exquisite.

Alaves felt aggrieved when handball claims against Samuel Umtiti were rejected following a late raid into the area, but, for all the visitors’ gallant efforts, earlier wasted opportunities meant they only had themselves to blame.