In a hugely entertaining match, Gonzalo Higuain's sixth-minute strike was all that separated the two teams at the break.
Jose Callejon's goal, 12 minutes into the second half, looked to have sealed the result for Real but a Xabi Prieto penalty and an Antoine Griezmann strike levelled proceedings with 12 minutes left.
Sami Khedira responded with a superb chip, but Sociedad, who were completely dominant in the latter stages, finally mustered an equaliser with captain Prieto's header giving them what could be a vital point.
With Valencia winning 1-0 against Granada, Sociedad slipped to fifth – two points behind the Mestalla outfit who occupy the fourth position that brings with it involvement in the Champions League group stages  – with one match of the Liga season remaining.
With nothing but pride to play for, Real Madrid manager Jose Mourinho made six changes to his side.
The likes of Cristiano Ronaldo, Karim Benzema and Xabi Alonso were all rested, with forwards Higuain and Callejon and midfielder Kaka just some of the players coming in.
Real Sociedad made two changes, with Mikel Gonzalez and Gonzalo Castro replacing the suspended Carlos Vela and omitted Liassine Cadamuro.
The visitors took the lead after just six minutes as a horrendous Mikel blunder gave Higuain the perfect chance to score.
The defender dallied on the ball, and failed to complete a one-two with a team-mate, chipping straight at Higuain who stormed forward before shooting past Real Sociedad goalkeeper Claudio Bravo.
Mikel almost made amends at the other end, putting the ball into the side netting following a corner, Agirretxe had two efforts on goal, and Griezmann forced Real Madrid goalkeeper Diego Lopez into a great save in an inspired spell of play.
Illarra's great ball over the top saw Griezmann in space and his header forced a terrific reaction save from Lopez, who then did well to deny Agirretxe moments later.
The chances kept coming for the hosts, with Illarra's header saved by Lopez, before Griezmann was only able to get a toe on a ball across the face of goal.
Real Sociedad did not deserve to be one goal down at half-time and Agirretxe went close again just after play resumed, hammering a hard and low effort at Lopez who saved well.
After Inigo Martinez nearly scored an own-goal, Real Madrid hit their opponents with the ultimate sucker-punch as an excellent Kaka cross was side-footed in by Callejon inside the six-yard box in the 57th minute.
Sociedad snatched a lifeline just six minutes later though, as Prieto's ball into the penalty area was carelessly handled by Sami Khedira.
Prieto himself stepped up to take the spot-kick and coolly slotted it, giving the players and the crowd hope of an unlikely comeback win.
And they should have been celebrating an equaliser in the 69th minute as Griezmann latched onto Agirretxe's ball and rounded Lopez, but could only shoot wide.
Griezmann did get Sociedad's equaliser though, as Carlos Martinez supplied a terrific ball that he netted at the far post in the 78th minute.
Real Madrid produced an immediate response, as a one-two between substitute Mesut Oezil and Khedira ended in the latter delightfully dinking the ball over Bravo and into the back of the net.
Sociedad were not disheartened though, as Prieto's bullet header forced Lopez in another fabulous save, before Griezmann had a goal wrongly ruled out for offside.
Agirretxe headed just wide with what looked to be the game's last chance, but there was more drama to come.
Another Carlos Martinez cross was headed back across the face of goal by Agirretxe, and Prieto was on hand at the far post to nod home, beating Lopez to the ball by a matter of inches.