Jose Mourinho dropped Iker Casillas to the bench in favor of Antonio Adan for the second game running, and matters seemed to be going according to plan when Karim Benzema put the hosts in front after only two minutes.
It all fell apart for Madrid and Mourinho four minutes later, though, as Adan conceded a penalty and was sent off for a professional foul, allowing Prieto to equalize from the spot. Sami Khedira put Los Blancos back in front, but Prieto pegged them back once more five minutes before the break.
The second half was just as eventful, as Ronaldo appeared to put the match out of reach with a quickfire double with 20 minutes remaining, but Prieto made matters tense with his third goal, before Dani Estrada's late red card ended the challenge of Sociedad for good.
Despite the victory, Madrid still remains in third place, 13 points behind leaders Barcelona, who can stretch their lead at the top further when it faces Espanyol at Camp Nou later on Sunday.
Mourinho’s decision to bench Casillas did not prove popular with the home support, who hailed the mention of the club captain while booing that of their coach during the pre-match lineup announcements. His choice proved to be costly six minutes in, as a poor clearance from Adan invited pressure from Carlos Vela, who was then tripped up inside the area by the keeper, who was given a straight red card.
The sight of Casillas readying himself on the touchline drove the fans into a frenzy, but after finally stepping between the posts after a lengthy delay, the club captain could do nothing to stop Prieto from converting the spot kick.In the 68th minute, los Blancos finally surged ahead for good. A fantastic clipped ball from Benzema released Ronaldo, who needed only one touch to calmly place the ball into the back of the net. Two minutes later, Ronaldo would seemingly put the result beyond any doubt with a swerving free kick from the corner of the box that flew into the roof of the net.
Sociedad wasn’t finished just yet, and Prieto ensured a nervy end to the game after latching on to Chori's through ball to complete his hat trick with 14 minutes remaining. Sociedad's hopes were put to rest once and for all in the 79th minute, though, as Estrada was shown his second yellow card for blocking Ronaldo on the wing, giving Madrid the boost they needed to close out the victory.