Sami Hyypia's side leaves it late to down the Spanish side and claim first its victory in this year's competition
The midfielder, who had been brought on six minutes from time, curled home from distance as the Bundesliga outfit erased memories of a 4-2 opening-game defeat to Manchester United.
Simon Rolfes nudged the hosts ahead just before the break but Carlos Vela's rebound from his own saved penalty leveled the scores in the second half.
And the Liga side saw its hopes of a first point in Group A stolen away by Hegeler late on as it followed up its loss to Shakhtar Donetsk with another defeat.
The home side started brightly and the game's first opportunity fell to the in-form Stefan Kiessling, who has five goals in seven Bundesliga games this season, but he fired straight at Claudio Bravo after going through one-on-one.
Leverkusen almost went ahead in the 20th minute when Rolfes' strike deflected off Sidney Sam and forced a smart stop from Bravo.
Sociedad created some chances of its own, though, and 12 minutes before the break Elustondo's superb effort was well kept out by Bernd Leno.
But it was Sami Hyypia's men who took the advantage into the interval, Rolfes firing home after his header from Sam's free kick had been parried by the goalkeeper on the stroke of halftime.
Their lead lasted less than 10 minutes into the second half, as Roberto Hilbert chopped down Vela and the Mexican stepped up to take the spot kick, which he tucked away at the second attempt after Leno saved the initial effort.
But, after weathering the storm, it was the hosts who prevailed when Hegeler found the top corner with a stunning last-gasp free kick that marked his side's 100th goal in the competition.