Atletico Madrid averted an embarrassing home defeat to minnows Eibar by drawing 1-1 thanks to a strike from teenage debutant Borja Garces deep in injury time but continued their poor start to the La Liga season.
Champions Barcelona fell behind following a thumping shot from Aritz Elustondo in the 12th minute from a set piece.
They then survived a mini onslaught from the home side in the second half before Luis Suarez levelled in the 63rd with a scrappy goal and Ousmane Dembele gave them a barely deserved lead three minutes later.
The fightback follows Barca's 4-2 win at Anoeta last January and makes them the only team to still have a perfect record in Spain's top flight, where they lead the standings with 12 points, two clear of Real.
Visiting coach Ernesto Valverde decided to start his side's arguably least favourite away trip without Philippe Coutinho and Sergio Busquets ahead of a jammed schedule of six games in 20 days.
That gamble appeared to have backfired when Elustondo smashed home following a knock down from a corner.
Valverde brought on Coutinho and Busquets early in the second half but their presence initially made little difference as Real Sociedad launched three counter attacks in quick succession, with only the presence of German goalkeeper Marc-Andre ter Stegen preventing the home side from doubling their lead.
Barely a minute after Ter Stegen had blocked a gaping chance for Juanmi, Uruguayan striker Suarez took advantage of some confusion in the area following a free kick and smashed home from close range to the disbelief of the home supporters.
The Catalans took the lead following another set piece, Dembele sending the ball skidding in after goalkeeper Geronimo Rulli had flapped at a corner and left his net unguarded.
Real Sociedad still had several chances to equalise in the final stages but could not keep their composure in front of goal, while Barcelona walked away from a ground where luck has so often deserted them with three scarcely earned points.
HUGE WIN
"I think you have to see a game like this to see how tough La Liga is," said Suarez.
"Last year we also came from behind to win here and eight or nine years ago we wouldn't win any games here. It's a huge win for our confidence."
Jordi Alba meanwhile paid tribute to his goalkeeper for keeping Barca alive.
"Ter Stegen was perfect today, that's why he's the best in the world. We always suffer here but the important thing is that we got the three points," the defender said.
Iker Muniain gave Athletic a deserved lead in the 32nd minute in Bilbao by bundling the ball home after Real failed to get back in time to defend a counter attack.
The home side had a slew of chances during an entertaining, end-to-end first half, while Real were twice denied by Athletic's impressive 21-year-old goalkeeper Unai Simon.
The visitors finally beat the youngster when Isco nodded home a cross from Gareth Bale in the 63rd minute as Real improved after bringing on midfield anchor Casemiro at the start of the second half.
Simon made two more outstanding saves to thwart Marco Asensio and Sergio Ramos although Athletic continued to counter, Inaki Williams smashing wide and the Basques being denied a penalty when the ball struck Casemiro on the arm while the Brazilian was on the floor.
The decision enraged Athletic supporters in a hostile atmosphere at San Mames, which was mirrored on the pitch as referee Jose Luis Gonzalez Gonzalez handed out eight yellow cards, six to Athletic players.
“This is a very difficult ground to come to, for the team they have and for how they play. They come looking for you, they press you man-for-man and make life hard for you and if you don’t find ways deal with that it’s tough,” said Real coach Julen Lopetegui.
“That’s what happened in the first half but we improved a lot in the second and did enough to win. It was a very intense game, Athletic played their part well and we did our job in the second half.”