Samu Omorodion had put the visitors ahead with just 18 seconds gone.
Robert Lewandowski got Barcelona out of jail as Alaves threatened to pile on further misery for the reigning LaLiga champions.
The 35-year-old Poland international headed home a second-half equaliser after Samu Omorodion had fired the visitors in front with just 18 seconds gone and then converted a late penalty to ensure an eventful afternoon at the Estadio Olimpico ended 2-1 to the hosts.
However, Samu was left to reflect on what might have been after passing up three further chances to add to his tally as Barca, who were without influential duo Gavi and Frenkie de Jong, turned in an abject first-half display before finally finding their feet.
The home side kicked off under some pressure after their their midweek Champions League defeat at Shakhtar Donetsk, which came in the wake of their El Clasico reverse and an unconvincing league win over Real Sociedad.
And they could hardly have got off to a worse start as they conceded inside the opening minute.
Ilkay Gundogan was robbed by Jon Guridi inside the Alaves half and he carved his way deep into Barca territory before picking out Javi Lopez, whose cross was swept past keeper Marc Andre ter Stegen by the 19-year-old Samu.
Things could have been significantly worse for Xavi’s men amid a shambolic start as they were repeatedly opened up by the visitors.
Samu fired into the side-netting after controlling Andoni Gorosabel’s pass, and then missed the target after the latter had split the home defence to send him one-on-one with Ter Stegen.
Shell-shocked Barcelona started to work their way into the game and Alaves keeper Antonio Sivera had to save from Lewandowski and Joao Felix.
But in the meantime, Lopez had scuffed a shot on the turn wide after catching defender Jules Kounde sleeping, and the France international was fortunate to escape for a second time when Samu fired after being muscled off the ball by the frontman.
Felix tried desperately to drag his side back into the game as time ran down, but Sivera remained largely untroubled and the locals made their feelings abundantly clear on the whistle.
Barca returned with much greater purpose and Joao Cancelo fired into Sivera’s midriff within three minutes, and they were back in it with 53 minutes gone when Lewandowski got ahead of defender Rafa Marin to power home a header from Kounde’s right-wing cross.
The visitors found themselves pinned back deep inside their own half, but almost profited from another Kounde error when he headed Ruben Duarte’s free-kick straight at Abdelkabir Abqar, although the defender was unable to convert.
Lamine Yamal tested Sivera with a swerving attempt, but the Catalans finally edged in front with 12 minutes remaining when, after Abqar had tripped substitute Ferran Torres in the box, Lewandowski emphatically dispatched the resulting spot-kick.