Real's victory means they lead the standings on 56 points after 26 games, with Barca slipping to second spot on 55.
Real Madrid showed their character by beating Barcelona 2-0 in Sunday's top-of-the-table El Clasico, leapfrogging their rivals at the La Liga summit after a week in which their pride had taken a beating at home and in Europe.
Brazilian teenager Vinicius Jr scored the opener in the 71st minute with a strike that deflected off Gerard Pique, flummoxing goalkeeper Marc-Andre ter Stegen who had made some jaw-dropping saves, and substitute Mariano added the second in added time.
Real's victory means they lead the standings on 56 points after 26 games, with Barca slipping to second spot on 55, while Zinedine Zidane's side also crucially have the better head-to-head record in the event both sides finish level on points.
Real swallowed chastening defeats by Levante in La Liga and Manchester City in their Champions League last 16, first-leg tie in the past week but in the second half they overwhelmed Barca, threatening on numerous occasions before breaking the deadlock.
"We deserve our victory for everything we did, in attack and defence," Zidane told reporters. "It has been a complicated week for us and we had the chance to turn things around and we did that.
"But this win also doesn't change anything. We have a long way to go and we have to continue. We've got three important points but we'll have more difficult games and we will be criticised again."
Barcelona had bossed the first period and twice could have taken the lead but were powerless to stop Real after the interval and their impotence was summed up when Lionel Messi raced towards goal but was easily tracked down by Marcelo.
Marcelo's tackle got as loud a cheer as the goals from Madrid's fans who had not been able to toast a league win over Barca at the Santiago Bernabeu since 2014.
The long-awaited victory was confirmed by an unlikely source in forward Mariano, who had only just come off the bench to make his first league appearance of the season.
Barca midfielder Sergio Busquets believed his side deserved better.
"We played very well in the first half then in an unfortunate move they score thanks to a deflection.
We had a great chance to open up a big gap but it wasn't to be," he said.
"There's a long way to go in the season and we have to remember the positive things and how well we played in the first half."
Barca coach Quique Setien had remarked before the game that Real were under greater pressure to win after they had surrendered a three-point advantage over Barca by drawing with Celta Vigo and losing to Levante.
They were left further frustrated by their 2-1 home defeat by Manchester City which has seriously jolted their hopes of remaining in the Champions League and put Zidane back under pressure for the second time this season.
The first half was end-to-end but lacked quality.
Barcelona created clear sights of goal for Messi and Arthur Melo, both of whose efforts were well saved by Thibaut Courtois.
Madrid's main threat was the electric but raw Vinicius, who routinely got down the left but rarely knew what to do next.
Real looked far more determined in the second half, and Isco forced Ter Stegen into an outstanding flying save and then saw a downward header scrambled off t he line by Pique.
The missed chances galvanised the home fans, however, who could sense their team were close to an opening.
There was a touch of fortune to the deflected opening goal, but Real's victory was thoroughly deserved.