Mikel Oyarzabal put the visitors ahead with just 10 minutes played from the penalty spot. Eduardo Camavinga responded with a powerful long-range shot on 40 minutes, and Luka Modric put Madrid ahead with a similar effort three minutes later, to see the home side go in ahead at half time.
- Don't have ESPN? Get instant access
- ESPN+ viewers' guide: LaLiga, Bundesliga, MLS, FA Cup, more
The result leaves Madrid on 63 points at the top of the table, eight ahead of their closest rivals Sevilla, who were held to a draw at Alaves 24 hours earlier. Coach Carlo Ancelotti made three changes to the team that had won 1-0 at Rayo Vallecano.
The win also gives Madrid momentum ahead of their Champions League knockout stage match against Paris Saint-Germain.
"We played almost a perfect game. It could be our best game of the season," Ancelotti said. "We go into [the PSG game] with a lot of confidence and hope. In our stadium we'll give our best. I don't know if that will be enough, I think so.
"It's a game that will give us a lot of hope for the next game on Wednesday. That's the intensity we have to have, that's the intensity the fans like. It's the kind of game where the fans help you to do your best. Yes, I think we can repeat it."
Real Sociedad knew a win would put them into the top four and started well, looking to hurt Madrid on the counterattack with the pace of forward Alex Isak. They took an early lead when David Silva was brought down by Dani Carvajal's clumsy challenge and Oyarzabal squeezed his penalty low past goalkeeper Thibaut Courtois.
Madrid's first attempt on goal was a free kick from David Alaba which deflected off the defensive wall before Camavinga's left-footed rocket from distance made it 1-1. It was the France midfielder's second goal for the club, after he found the net on his debut back in September. Benzema had the ball in the net seconds later, only to be denied by a narrow offside call.
Rodrygo had a close-range shot saved, and from the resulting corner, Modric put Madrid in front. The corner kick was taken short, and when Benzema found Modric, he stepped inside Silva before curling into the top corner.
After the break Madrid increased the pressure as Casemiro tested La Real keeper Alex Remiro with a fiercely struck free kick, Benzema had an effort saved after a clever feint and Vinicius Junior saw a cross deflected into the side netting.
Benzema had a second goal ruled out -- this time because Vinicius Junior had strayed offside in the build up -- before he made it 3-1 with a penalty kick after VAR spotted that the Brazil winger had been fouled just inside the area.
Asensio came off the bench after 77 minutes and completed the turnaround just two minutes later, slotting past Remiro after Casemiro had released Carvajal down the right.
"It was an important game against a team that always hurt us. They always play good football. But there's a lot of league left, a lot of games, I think there are still 30 points to play for. They're three important points and we have to go game by game," Casemiro said.