The hosts made one change from the side that dispatched Real Valladolid last weekend, with manager Zinedine Zidane handing Isco his first league start since November.
Toni Kroos also made his 309th appearance for Los Blancos, making him the German with the most appearances in the club's history.
A highly tactical match saw Real Madrid hog most of the possession but they failed to make it count. Meanwhile, Real Sociedad used the speed of Alexander Isak to hit the capital side on the counter.
The first big chance of the first half came when Lucas Vazquez and Luka Modric combined well down the right flank. This allowed the Spain international to send a lobbed cross into the box.
Mariano Diaz could, however, not take advantage as he headed the ball onto the crossbar. Marco Asensio showed great technique to control the rebound but saw his goal-bound shot deflected behind for a corner.
The visitors had several chances on the counter but were let down by poor decision-making in the final third. They did not register a shot on target until late in the first half.
Zidane made a tactical change at the break, with Casemiro dropping back into defense, while Vazquez and Ferland Mendy played as wing-backs.
Real Sociedad started the second half on the front foot and won four corner kicks in quick succession, with Real Madrid struggling to hold on to possession.
Real Sociedad finally got the goal that their bright start deserved when Nacho Monreal delivered an excellent cross to the far post, which Portu sent beyond Thibaut Courtois with a pristine header.
This prompted Zidane into action, and he made three changes on the hour mark. The entire front three was hauled off, with Vinicius, Rodrygo and Hugo Duro coming on in their stead.
Rodrygo was making his return from a long-term injury that left him sidelined for several months. This was also Vinicius' 100th appearance for Real Madrid, making him the fourth-youngest player to achieve this milestone.
Having weathered the initial storm at the start of the second half, Real Madrid slowly seized the initiative and began to ask all the questions.
Casemiro, in particular, was guilty of missing several gilt-edged chances, while Rodrygo also sent a shot narrowly wide.
A deserved equalizer came in the 89th minute when Valverde's exquisite backheel set Lucas Vazquez on his way. The 29-year-old then sent yet another cross into the box and in the ensuing chaos, Vinicius popped up to bundle the ball over the line.
The victory saw Real Madrid move up to 53 points, five behind city rivals Atletico Madrid ahead of their crunch fixture at the Wanda Metropolitano next week.
Here are five talking points from the highly entertaining fixture.
#5 Two points dropped or one gained?
Real Madrid came into this clash six points behind Atletico Madrid, who still have a game in hand.
A victory here would have seen them reduce the deficit to three. It would have also handed Los Blancos the advantage heading into the Madrid derby.
However, Zidane's side fluffed their lines, leaving Los Colchoneros calling all the shots in what is set to be one of the most thrilling title races in a while.
Despite failing to get the job done, the manner in which Real Madrid snatched a point came as a relief to fans of the club, as defeat was a genuine possibility with less than a minute to go.
In the context of the title race, this represents a two-point drop. However, on evidence of how the game went, Real Madrid can count themselves lucky to have gotten something against Real Sociedad.
#4 Portu continues fine run against Real Madrid
Christian Portu's well-taken goal was his 7th of the current campaign. It also ensured that he continued to be a thorn in the flesh of Real Madrid.
Having scored two winning goals against the Bernabeu outfit while in the colors of Girona, the 28-year-old came to the fore once again.
Despite the goal not being a match-winner unlike his previous two goals, Real Sociedad left the capital with an invaluable point.