Philippe Montanier's men put in a valiant display to come from behind twice in order to secure a valuable draw which keeps them in the race for Champions League qualification
Gonzalo Higuain put los Blancos ahead inside six minutes and despite a valiant fight from the hosts which saw them control the game for large parts, Jose Callejon added a second after the break. Xabi Prieto and Antoine Griezmann brought the Basques level and though it looked as if Sami Khedira had won it for the visitors late on, Prieto popped up with a priceless stoppage-time equaliser.
Jose Mourinho made six changes to the team which suffered defeat in the Copa del Rey final last weekend and it only took six minutes for one of those replacements to open the scoring.
Mikel Gonzalez hesitated in possession in front of his own goal and a clumsy pass saw him gift the ball straight to Higuain. The Argentine thanked him by racing through on goal to slot a cool finish past Claudio Bravo and into the bottom corner.
Montanier's men were not fazed by going behind and were only denied an equaliser by an irrepressible Diego Lopez. The former Sevilla keeper readjusted excellently to keep Griezmann's header out after 20 minutes and soon after he turned Imanol Agirretxe's nodded effort over the bar.
Shortly before the break, Alberto de la Bella latched onto Asier Illarramendi's chipped pass and rolled the ball across the box, but Griezmann stretched to get a touch and inadvertently took it away from Agirretxe who was awaiting a simple finish at the back post.
The second half continued in a similarly exciting manner, with Kaka failing to bend his shot on target from the top of the box before Lopez parried a thunderous cross-goal effort from Agirretxe.
But it was los Merengues who struck next as Kaka bided his time on the left wing before finally threading in a magnificent cross upon spotting the run of Callejon who, one-on-one with the keeper, steered the ball into the corner of the net with his first touch.
Montanier's side were offered a route back into the game as Khedira handled the ball inside the area with 63 minutes played. Prieto was given the responsibility of the penalty and he showed nerves of steel to roll it into the bottom corner.
Six minutes later the game should have been level as Griezmann latched onto Agirretxe's scything through-ball. The Frenchman rounded the keeper but was unable to wrap his foot around the ball and send it into the empty net.
Agirretxe was unfortunate not to find the net from Diego Ifran's free kick, but with 12 minutes remaining the Basques found their equaliser. A quick move down the right ended with Carlos Martinez sending a low ball to the back post where Griezmann finally got his goal with a simple tap in.
The game was only level for two minutes, though, as Germany internationals Khedira and Mesut Ozil combined with the former dinking a delightful finish over Bravo to regain his side's lead.
But the same defiant spirit that Sociedad had displayed earlier in the game shone through in stoppage time as Prieto bundled in an equaliser at the far post despite Lopez's best efforts to deny him.
A draw still means that the San Sebastian outfit will need results elsewhere to go there way if they are to secure a return to the Champions League, while Madrid fall 15 points behind champions Barcelona following their derby win over Espanyol.