Barcelona needed a late winner from Frenkie de Jong to edge past Alaves in La Liga on Sunday while Real Madrid gave hope to their title rivals by drawing 2-2 at home to Elche.
De Jong strikes late for Barca after Real Madrid pinned back by Elche
Frenkie de Jong (right) celebrates scoring the winner for Barcelona against Alaves on Sunday.
De Jong's 87th-minute winner at Mendizorrotza was the high-point of an otherwise uninspiring performance from Barca but it also secured a crucial 1-0 victory in their bid to catch the top four.
"When we lost to Real Madrid in the Super Cup we left satisfied with the game but we didn't win - this time we're not satisfied with the game but the three points are gold," said Xavi Hernandez.
Barcelona move up to fifth, with Atletico Madrid still one point ahead in fourth. The two teams meet next at Camp Nou on February 6.
"We're in the fight and these results will come in very handy," said Xavi.
Real Madrid, meanwhile, squandered an opportunity to move six clear of Sevilla as Karim Benzema missed a penalty and then went off injured at the Santiago Bernabeu.
It could have been worse for Madrid, who were two down with 11 minutes left yet managed to rescue a point thanks to a Luka Modric penalty and a 92nd-minute header from Eder Militao.
Lucas Boye and Pere Milla had put Elche in sight of a shock victory.
But two dropped points against a team fighting for survival this season will have come as a welcome bonus for Sevilla, who would have expected to be punished for their own draw at home to Celta Vigo on Saturday.
"The match was a bit all over the place," said Real coach Carlo Ancelotti.
"We dropped two points so we can't be happy but in general we have a break now and we're in a good position. We're in the Copa del Rey, the Champions League and we have a good position in the league."
Benzema's injury is perhaps the biggest concern. The Frenchman was clutching his left hamstring as he walked down the tunnel in the second half and Ancelotti said he would undergo tests on Monday.
Madrid will hope it is nothing serious, with their Champions League first leg against Paris Saint-Germain just over three weeks away.
Eden Hazard was given his own opportunity after Ancelotti handed him a rare start and while the Belgian was certainly one of Madrid's more creative players, he went off in the 79th minute, just before his team's revival began.
Before kick-off, all of Madrid's players came out wearing number 11 shirts in tribute to Paco Gento, who died aged 88 on Tuesday. On display were Gento's 12 league trophies and six European Cups.
Real Madrid did just enough to create a handful of chances in the first half but overall they were lethargic, their passing sloppy and the sharpness of recent performances lacking.
Still, it looked like it would be enough when Vinicius Junior was hacked down by Helibelton Palacios in the 33rd minute and the referee pointed to the spot. The usually dependable Benzema, though, blazed over.
The miss galvanised Elche, who had defended resolutely and then gave themselves something to defend.
Yohan Mojica sent a ball down the left for Fidel to run onto, and he crossed into the area where Boye was free to nod in.
Elche were not unduly troubled and in the 76th minute they made it two, with the excellent Boye twisting away from David Alaba and shifting right to Milla, who drove into the far corner.
Madrid looked out on their feet but in the 82nd minute they were handed a lifeline, as Alaba's flicked header caught Milla on the hand and, in Benzema's absence, Modric slotted in the penalty.
There was time for an equaliser and in the 92nd minute, it came, as Vinicius retrieved an overhit pass off the line and crossed for Militao, who headed in. With two minutes left, Madrid wanted a winner but time ran out.
Barcelona left it late too and could have been behind had Pere Pons not floated a tame finish into the hands of Marc-Andre ter Stegen in the first half.
Luuk de Jong went through for Barca but took too long and then Alaves' Joselu headed wide at the front post, with the game seemingly heading for a stalemate.
But Barca found a way with three minutes left, Jordi Alba clipping a delightful pass over the top for Ferran Torres, who showed the composure to tap it left, where De Jong had an easy finish.