Julen Lobete fired inside the near post in the 90th minute to snatch a 1-0 victory and spark pandemonium at the Reale Arena, where the fans and players celebrated like they had won a trophy.
In fact, in jubilant scenes after the final whistle, the players paraded the 2020 Copa del Rey trophy - won earlier this year in the postponed final against Basque rivals Athletic Club - in front of their own fans for the first time.
And while Real Madrid face Barcelona in the first Clasico of the season next Sunday, Real Sociedad's game away at reigning champions Atletico Madrid now has more riding on it at the top of the table.
Atletico are also three points behind La Real.