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.