Defender Clement Lenglet scored the winning goal and was sent off as Barcelona beat Real Betis to close the gap on La Liga leaders Real Madrid.
The champions twice came from behind to level before Lenglet headed in Lionel Messi’s 73rd-minute free-kick.
Sergio Canales’ sixth-minute penalty gave Betis an early lead but Frenkie de Jong levelled three minutes later.
Nabil Fekir’s fine strike restored the hosts’ advantage only for Sergio Busquets to make it 2-2 at half-time.
Trailing 3-2, Betis were reduced to 10 men after Nabil Fekir received two yellow cards in quick succession but Lenglet’s dismissal made for a tense finale.
It had been a difficult week for Barcelona after they were dumped out of the Copa del Rey at the quarter-final stage by Athletic Bilbao and the club’s sporting director Eric Abidal publically criticised the players for not working hard enough.
Things worsened for Quique Setien’s side after Lenglet handled in the box inside the opening five minutes and former Real Madrid player Canales confidently converted from the spot.
But Barcelona fought hard to twice level, De Jong and Busquets both also converting from Messi assists, before sustained pressure in the second period eventually wore the hosts down.
Setien’s chasing side remain in touch with Zinedine Zidane’s Real Madrid, who they will face in La Liga in three weeks time.