Real Sociedad remained on top after the break but Barcelona found more stability, gaining strength at the back and closing some of the space lost to Barrenetxea and Kubo early on.
Pedri returned from injury in the second half and replaced Lewandowski for the first time since August as Xavi sought more control.
The final contribution to an impressive performance from the 21-year-old forward was Ter Stegen who pushed Barrenetxia’s volley away from the edge of the box.
Substitute Ferran Torres fired a shot from the edge of the box, ending Barcelona’s night to that point, before the champions created their first real chance in stoppage time.
Pedri cleverly passed the ball to Gavi, but Ramiro prevented the midfielder from scoring a goal that should have found the net.
It looked as if their chances of snatching victory were over, but centre-back Araújo was in the right place at the right time to pull off the robbery.
After this defeat, Real Sociedad are in sixth place, Real Betis have gained the position above them by defeating Mallorca.
“Generally we were better than them, we didn’t waste our chances and they scored what they had,” Oyarzabal told Movistar.
“I think it’s worse to lose without showing up, to lose without playing well… We all wanted to win and we had chances to win, but if you have to lose, I prefer to lose like this.”