Roberto Soldado had given Ernesto Valverde's men the lead in the first half, but a terrific volley from Inigo Martinez, a neat finish from Chori Castro, and a double from Imanol Agirretxe saw the hosts walk out with all three points, despite receiving a late fright from Jonas.
Carlos Vela almost gave his side the perfect start after just two minutes. The hosts typically counterattacked at pace down the left and the ball eventually came to the Mexican on the right-hand side, but his whipped strike towards the far corner went just the wrong side of the post.
Valencia responded with a decent chance of their own four minutes later, though. Jeremy Mathieu curled an accurate 25-yard free kick over the wall which looked destined to nestle in the corner, but goalkeeper Claudio Bravo managed to get across goal to beat the set-piece away from danger.
Both sides looked more than capable of opening the scoring, but it was the visitors who struck the first blow 25 minutes in. Aly Cissokho skipped past a couple of challenges down the left flank and got to the bye line before curling a superb cross to the front post, and the predatory Soldado got in front of his marker to glance a header into the bottom corner.
Things could have got so much worse for Sociedad four minutes later when Bravo rushed off his line and appeared to touch the ball with his hand outside the box. But the goalkeeper was saved from a potential red card when the referee waved play on, having missed the offence.
The home side looked buoyed from their slice of luck, and got back on level terms 10 minutes before the end of the first half. A quick corner kick saw Castro pick up the ball on the left flank and float a cross to the back post for Martinez. The 21-year-old shook off the attention of Ricardo Costa and wonderfully side-footed the ball on the volley into the top right corner.
In the second half it was Valencia who benefited from the lenience of referee, Fernandez Borbalan. A cross came in from the right-hand side and Cissokho appeared to bat the ball away with both hands inside the area, but the official inexplicably failed to award Sociedad the penalty.
The Basque side were not downheartened, though, and edged ahead with 18 minutes remaining through a sublime counterattack.
An Ever Banega free kick was cleared out of the box, and Agirretxe burst out his own half before exchanging a scintillating one-two with Castro. The 26-year-old then galloped down the right wing before sliding a perfect pass back to the Uruguayan, who slotted in past the static Diego Alves.
The match looked to have been put to bed five minutes from time when Xabi Prieto clipped a lovely cross to the back post for Agirretxe, who made no mistake and smashed a volley past Alves in the Valencia goal.However, Jonas pounced on a mistake from Bravo to head home from close range to make it 3-2, setting up a scintillating climax.
It was to be Sociedad's night though, and they made it 4-2 in the last minute when Agirretxe ran through on goal and wonderfully chipped Alves, sending the Anoeta faithful into raptures. Sociedad now move five points clear of Malaga and Valencia in fifth and sixth place in the league respectively, with the prospect of Champions League football looking more likely as the weeks progress.