Philippe Montainier's side reversed the scoreline with two 90th minute goals to earn an incredible victory at San Sebastian over the strongly favored visitors.
Injury time goals from Carlos Vela and Diego Ifran helped Real Sociedad clinch a dramatic 3-2 win over Malaga in San Sebastian, in Sunday's La Liga encounter.
A Martin Demichelis own goal gave the home side the lead before Salomon Rondon and Seba Fernandez looked to have won it for the visitors.
That was until Vela's screamer leveled scores late on and substitute Ifran grabbed all three points at the death.
Despite the polarity of its league table positions, Sociedad gained a slight edge with through its quick counterattacks at the beginning of the match. The club took advantage of this edge to open the scoring.
Playing down the left, Daniel Estrada whipped in a brilliant cross which found Imanol Agirretxe who majestically headed the ball past Willy Cabalero but not the crossbar.
Bouncing back off of the woodwork, the ball deflected off of an unfortunate Demichelis and into the back of the net to open scoring in the 10th minute.
The away side did not take long to equalize. A free kick found an unmarked Isco on the right and curled in a cross for Rondon who easily found the back of the goal with a header from only a few yards out.
From this point, the fixture featured a flurry of end-to-end action as both sides looked to catch their opponents with pacy counterattacks which gave the spectators what they wanted to see.
Antoine Griezmann troubled Manuel Pellegrini's men as his fine dribbling opened up space for David Zurutuza who riffled a strike at goal and forced a fine save out of Caballero just before halftime.
In the second half, Malaga controlled the action, pressuring the home side high up the field and making it difficult for Philippe Montanier's men to escape their own half.
Duda threatened from range, but it was a horrid mistake from Gonzalez that gave Malaga the advantage. Thinking that he was alone in his 18-yard box, Gonzalez took his time in playing the ball. With his back turned, he didn't see a surging Fernandez, who stole the ball from the unfocused central defender and tapped it into the back of Claudio Bravo's goal.
The home side fought for the equalizer and earned it through a wonderful, last minute strike from Vela.
The Mexico international sent a roaring bicycle kick into the back of Caballero's goal after picking up on a flick inside the box.
The home side was not finished and in dramatic fashion, Ifran grabbed the winner in the last seconds after finding space for himself between the center backs in the box and striking past Caballero once more.
With the victory, Real Sociedad moves out of the relegation zone but a disappointed Malaga remains fifth and is left to wonder how it allowed the advantage to slip.