Barca needed a late winner from Arturo Vidal to beat bottom-club Leganes 2-1 after Luis Suarez headed home a Lionel Messi free-kick to cancel out a brilliant opener from Leganes forward Youssef En-Nesyri.
Madrid were behind after 110 seconds against high-flying Real Sociedad but Karim Benzema scored his sixth goal in five games, before Fede Valverde and Luka Modric wrapped up a 3-1 win in the second half.
It means Atletico Madrid lost further ground by being held to a 1-1 draw at Granada, with Real Sociedad remaining fifth, five points off the top. Sevilla, in fourth, play at Real Valladolid on Sunday.
Real Sociedad face test of credentials against in-form Real Madrid
Madrid's comeback was overshadowed by the whistles for Bale after his controversial celebration following Wales' win over Hungary last week. He celebrated with a flag that read: "Wales. Golf. Madrid. In that order."
The fans jeered when his name was announced before kick-off and even louder when he came on as a substitute in the second half.
"I can't tell you it's fair or unfair," said Zidane after the match. "But we need our fans to be with us. I can't control it, neither can Gareth or anyone. But Gareth came on and he played very well."
Without Bale, Benzema continued his excellent form with another goal and an assist for Modric late on. In between, Valverde gave Madrid the lead with a deflected shot from the edge of the area.
Madrid's fans were also given the chance to see Martin Odegaard, their 20-year-old Norwegian loanee at Real Sociedad, who has been key to their strong start to the season.
Odegaard impressed, with one through ball in the first half even drawing gasps of approval from the home support.
Barcelona's gritty victory will come as a relief to coach Ernesto Valverde too ahead of a testing month for his side.
They play Borussia Dortmund on Wednesday in the Champions League and a goalless draw against Slavia Prague earlier this month means qualification from Group F is no longer guaranteed.
Benzema stars as Madrid put five past limp Leganes
After Dortmund, Barca then play at Atletico in La Liga to start a month that will include trips to Inter Milan in the Champions League and Real Sociedad in La Liga before the season's first Clasico.
"It was a big win because the game was very difficult," Valverde said. "The pitch was dreadful, there was a lot of wind and they scored early.
"I don't want it to sound like an excuse but it made it hard and still we were able to win."
The home side made the perfect start as En-Nesyri beat Gerard Pique with a wonderful early strike.
Pique has spent the international break juggling football with the Davis Cup, the revamped tennis tournament in Madrid that he is organising through his marketing company.
"There is more noise outside the club than inside," said Pique after the match.
"I think it's got a bit out of hand -- whether I'm in Madrid, eating here, having dinner there -- it's all part of the circus. But I do my job. I come here, I play football. And that's it."
One pass from Roque Mesa was enough to set En-Nesyri free against the 32-year-old in the 12th minute. Pique jostled but was taken by surprise as En-Nesyri nipped inside and bent a shot into the far corner.
Suarez went close, Pique hit the post and Suarez did find the net, glancing in Messi's clipped free-kick for his ninth goal of the season.
Barca's second owed much to luck but it came from another cross. Pique rose to head in but the ball missed him and cannoned off the foot of Ruben Perez. Vidal was waiting on the line to prod in.
Atletico were unable to find a winner as they played out their seventh draw of the season, the joint most in the division.
Ronan Lodi scored his first La Liga goal after being slipped though by Hector Herrera but Herrera was at fault for the equaliser, losing his marker as German Sanchez powered in a superb header to earn Granada a point.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ