Vallejo was then shown his red card for a handball on the line and, while Willian Jose could not convert the penalty, Joseba Zaldua and Ander Barrenetxea scored in the second half to give Sociedad a comfortable victory.
Relive how the 90 minutes of action unfolded with Sports Mole's live text coverage below.
Los Blancos are aiming to make it back-to-back league wins in the Spanish top flight to keep alive their slim hopes of finishing above Atletico Madrid in second place.
Sociedad have won two matches on the spin, meanwhile, and find themselves sitting comfortably in eighth place ahead of this match.
STARTING XI: Rulli; Zaldua, Moreno, Llorente, Munoz; Pardo, Zubeldia, Merino; Barrenetxea, Willian Jose, Oyarzabal
SUBS: Bautista, Rodrigues, Illarramendi, Miguel Angel Moya, Januzaj, Juanmi, Raul Navas
STARTING XI: Courtois; Carvajal, Nacho, Vallejo, Marcelo; Isco, Casemiro, Kroos; Asensio, Benzema, Diaz
SUBS: Modric, Valverde, Mariano, Vazquez, Vinicius Junior, Llorente
Sociedad responded well to that early setback, coming close through on-target attempts from Mikel Merino and Mikel Oyarzabal, the latter turning on the edge of the box and unleashing a powerful half-volley for Thibaut Courtois to deal with.
Seconds after play resumed, Sociedad were back on level terms thanks to a well-worked goal that culminated in Willian Jose flicking the ball in behind for Merino to convert.
That led to the referee sending off the centre-back and awarding a penalty, which Willian Jose failed to convert - the forward's powerful shot being too central, allowing Courtois to keep hold of it.
REAL SOCIEDAD SUBS: Bautista, Rodrigues, Illarramendi, Miguel Angel Moya, Januzaj, Juanmi, Raul Navas
REAL MADRID SUBS: Modric, Valverde, Mariano, Vazquez, Vinicius Junior, Llorente