Barcelona's Ronald Araujo headed a stoppage-time goal to snatch a 1-0 win at Real Sociedad on Saturday as they kept pace with the leaders in LaLiga after being outplayed by the hosts.
Real Sociedad had chances in the first half but were foiled by a series of saves from Marc-Andre ter Stegen.
Barca's best opportunity came from Fermin Lopez after a foul on Joao Felix before the break.
Sociedad keeper Alex Remiro then made a brilliant save to deny Gavi and Ronald Araujo had an effort disallowed for offside before he popped up with the winner in the 92nd minute.
The victory puts Barcelona in third place on 27 points from 12 games, four points off leaders Girona who won 4-2 at Osasuna earlier on Saturday. Real Sociedad are sixth on 19 points.
Barca manager Xavi Hernandez was not happy with his side's performance despite the last-gasp victory.
"It is simply unacceptable that the team failed to put in the required intensity from the first second. And the negative aspects turned viral in the second half," he said.
"It wasn't until the last five minutes that we finally started to show some hunger and began to look comfortable.
"... ultimately the way we won was spectacular and that will be a huge boost for our confidence."
Barca play Shakhtar Donetsk in the Champions League on Tuesday in Hamburg, while Sociedad host Benfica on Wednesday.