Published: 2019-01-07 04:14:26 BdST
Willian Jose put the Basques ahead in the third minute and after Madrid missed a series of clear chances, had two penalty appeals waved away and saw Lucas Vazquez sent off, midfielder Ruben Pardo sealed their fate with a headed goal in the 84th.
Many home fans flocked away early in dismay while others greeted the final whistle with deafening boos after Real Sociedad, in their first game under new coach Imanol Alguacil following Asier Garitano's sacking, won at the Bernabeu for the first time since 2004.
Madrid, who drew 2-2 with struggling Villarreal on Thursday, are fifth on 30 points after 18 games in the La Liga standings, seven adrift of leaders Barcelona who were in action against Getafe later on Sunday.
Real Sociedad climbed from 16th up to 11th.
Jose Willian smashed his spot-kick down the middle of the goal beyond Thibaut Courtois and although Real rallied with a glut of chances throughout they somehow failed to find the net.
Karim Benzema missed a gilt-edged opportunity by firing wide of the far post with the goal gaping, while Vazquez struck the other post with what looked like an intended cross.
Real spurned a triple chance immediately after the interval as Sociedad goalkeeper Geronimo Rulli thwarted Vinicius Jr. and Raphael Varane from close range, and their task was made all the harder when Vazquez was dismissed in the 61st minute for a second booking.
"Everything went against us today, we had a terrible start, a very unfortunate play in the opening minutes and every error at this level is punished dearly," said Real coach Santiago Solari after his second league loss since succeeding Julen Lopetegui at the end of October.
"We did everything to turn it around, we had a lot of chances none of them went in and in football it's the goals that count. We also had a penalty appeal which no-one can understand why it wasn't given.
"I give the benefit of the doubt to the referee for the first incident, but the second one is a penalty every day of the week."