Barcelona, whose goals all came in the first-half against their city neighbours, remain 16 points clear of their bitter rivals and eleven ahead of second-place Atletico Madrid who drew 1-1 with Mallorca.
Madrid captain Casillas was left out for the second consecutive game but was called upon after just five minutes following a penalty conceded by his replacement Adan Garrido who was red carded.
Xabi Prieto, who was to grab a hat-trick, scored from the spot-kick to equalise after Karim Benzema had put Madrid ahead in the second minute with Sami Khedira then restoring the lead for Jose Mourinho's side after 35 minutes.
Prieto struck again before half-time before Ronaldo came to the rescue with a brace after the restart.
Prieto hit his third with 14 minutes to go but Sociedad also finished with 10 men as Daniel Estrada was given a second yellow card.
After the game Mourinho said he was unconcerned about receiving abuse from the crowd.
"Perfect. Let them whistle me before the match and then support the team as they are doing. I think the whistles are for leaving Casillas out and also because we are not achieving our aims in the championship," he said.
"There are others who didn't applaud and are not happy with his (Casillas') performances. If I am not doing well it is normal that they whistle and it is something you have to live with. I don't want to be a hero independently of my performances."
Madrid faced an injury crisis at the back with Pepe, Fabio Coentrao, Marcelo and Raul Albiol all injured and Sergio Ramos suspended.
They got the perfect start with Khedira finding Benzema in space in the centre of the penalty area and he found the corner with a clinical finish.
But if the Bernabeu crowd were expecting to then see a comfortable victory after such an inconsistent season they were badly mistaken as only three minutes later Adan conceded the penalty for the visitors to draw level.
Adan's poor pass to Ricardo Carvalho went to Carlos Vela who bore down on goal and was upended by the shot-stopper. The referee pointed to the spot and also dismissed Adan which meant Casillas would play after all.
The player nicknamed 'Saint Iker' by Spain fans for his exploits in the recent successes of the national side was unable to make the perfect start as Prieto fired home the penalty.
Madrid went back ahead with Khedira flicking in a shot by Carvalho from the edge of the area but they were never comfortable at the back and Prieto got his second when a Vela strike fell to him and he drove the ball past Casillas.
After the break the game hit a lull before Ronaldo responded with a double.
Benzema hit a ball over the top and he finished clinically and then a couple of minutes later he struck a free-kick into the top corner.
Sociedad didn't give up with Xabi Prieto latching onto a Chory Castro pass before beating Casillas but their hopes of an equaliser were hit by a red card for Estrada.
At the Camp Nou, Pedro Rodriguez hit a double with Xavi Hernandez and Lionel Messi also scoring in a rampant first half as Barca welcomed coach Tito Vilanova back after cancer surgery.
"I would like to thank everyone for their support. This club has had a lot of knocks in the last couple of years but I always want to take the positive approach. What has happened to me could have happened to anyone," said Vilanova.
"This is not over yet and there will be days that I can take training and others I can't but I want the media to realise that this illness is mine and it is private."
Vilanova chose to play Andres Iniesta in his three-man attack and leave Alexis Sanchez and David Villa on the bench against Espanyol who were unbeaten in four games under new coach Javier Aguirre.
Iniesta crossed for an unmarked Xavi to put Barca ahead after 10 minutes and Cesc Fabregas pulled the ball back for Pedro to score from close range.
The visitors had minimal possession but still Sergio Garcia could have put them back in the game but flashed wide after Carles Puyol missed the ball.
Pedro produced a neat finish to beat keeper Francisco Casilla midway through the first half and then Messi struck from the penalty spot after Fabregas was felled by Casilla.