Xabi Prieto opened the scoring for the Spanish side when his header evaded Willo Flood at the near post.
Peter Pawlett found the net before half-time then Mark Reynolds headed Aberdeen into the lead.
However, as the legs of Derek McInnes’ men began to tire, Prieto’s penalty levelled the score before Markel Bergara headed in a late winner.
For all that it was a disappointing end to their campaign, Aberdeen will look back fondly at victories over Daugava Riga and Groningen.
And McInnes will be buoyed by how well his side competed against a team who are far superior to most of the teams they will face this season.
The sound of 5,000 hooters handed out to fans before the game was the soundtrack to a packed Pittodrie and the game began at a frantic start with both sides passing well on the slick pitch.
However, the Dons nearly found themselves behind. Flood’s weak pass-back was intercepted but, to the relief of the home support, the shot was blocked.
Ryan Jack found the net from a Niall McGinn corner, but he and two of his team-mates were all judged offside.
The threat of the Spanish side was apparent as they continued to break quickly and, when they launched a counter attack from a corner, Shaleum Logan had to be alert.
It only delayed the opening goal. Captain Prieto met a corner at the near post and flicked it into the net.
That left the Dons with an even more daunting task, with four goals now needed to make the next round. It did not appear to faze them and they continued to take the game to Sociedad.
Logan’s long-range shot was well held by Enaut Zubikarai, but the Dons needed something to take into half time and they got it when Pawlett drew them level.
McGinn cut in on the left-hand side and his delivery caused havoc in the Sociedad box. David Goodwillie’s initial shot was untidy, but it fell kindly to Pawlett, who bundled the ball into the net.
The momentum from that goal continued into the second half and Jonny Hayes’ driving run through the middle had the Aberdeen supporters screaming for a penalty when he hit the deck while outmuscled by two defenders.
Much better was to come when McGinn found space on the left-hand side and picked out Reynolds, who headed beyond Zubikarai.
The Spanish looked stunned as Pittodrie rocked all around them. Flood grazed the crossbar with a shot before Ruben Pardo did similar for Sociedad.
Substitute Sergio Canales twice went close, but it was the Dons who remained the more industrious.
However, Logan’s tiring legs let him down as he was caught out by the run of Alberto De La Bella. His sliding challenge took the left foot of the Spaniard to concede the penalty.
Prieto stepped up and cheekily chipped it down the middle.
Aberdeen looked dead on their feet as the clocked ticked down and it was a case of could they hold on for the draw, but Canales’ flighted ball from the right found the head of Bergara, who gave Jamie Langfield no chance.
Source: BBC Sport