Barcelona striker Luuk de Jong scored a header in added time to give his side a 3-2 win at struggling Levante after a remarkable, end-to-end game in which his side gave away three penalties.
Barca are the first team in LaLiga to win a match after conceding three penalties and De Jong's last-gasp goal saw them record a seventh consecutive league win, lifting them into second in the standings on 60 points after 30 games.
But they are still a long way behind leader Real Madrid, which has 72 points from 31 after beating Getafe 2-0 at home on Saturday. Levante is 19th on 22 points.
Levante took a surprise but deserved lead against a lacklustre Barca in the 52nd minute when captain Jose Luis Morales scored from the spot after a foul by Dani Alves.
Moments later the host earned a second penalty, for a handball by Eric Garcia, who had prevented Levante from taking the lead in the first half when he scrambled a shot from Morales off the line.
This time striker Roger Marti stepped up to take it and his effort was saved by Barca goalkeeper Marc-Andre ter Stegen. The visitor quickly made Levante pay, Pierre-Emerick Aubameyang heading home a cross from Ousmane Dembele in the 59th minute.
Teenage midfielder Pedri then gave Barca the lead in the 63rd, thumping a first-time shot into the bottom corner after being teed up by 17-year-old Gavi, who had also been hauled on from the bench in the second half.
Levante then won a third penalty of the second half when Dani Gomez latched on to a through ball and was tripped by Barca defender Clement Lenglet. Gonzalo Melero assumed taking duties and made no mistake against Ter Stegen to level in the 83rd.
But there was time for one final twist in an enthralling encounter when substitute De Jong connected with a Jordi Alba cross and headed into the bottom corner in the second minute of added time.
"The fact we won while conceding three penalties shows we are very competitive and have a winning mentality," said Barca coach Xavi.
"I was concerned about this game because Levante are a difficult side with great players and they have beaten sides like Villarreal and Atletico Madrid. We've earned three golden points that keep us in the fight."
But when pressed on whether Barca had a chance of catching runaway leaders Real, the coach added: "It's very difficult because Real Madrid seldom slip up. But if they drop a few points in the next two weeks we can start to believe a little more."