The Blaugrana took an early lead through Gavi but Espanyol struck back with goals from Sergi Darder and Raul de Tomas.
Barca were heading for defeat until Luuk de Jong grabbed an equaliser deep into injury time.
It could be a crucial goal as it ensured that Barcelona ended the week in fourth place.
This result consolidated Betis’ position in third over those chasing beneath them.
Valencia‘s hopes of fighting their way back up towards the Champions League places were probably ended for good as they lost 2-1 at Alaves.
In conjunction with Sevilla’s 2-0 win over Elche on Friday, Carlo Ancelotti’s side have seen their lead cut to just four points.
They were unfortunate not to get the victory against Villarreal, with home goalkeeper Geronimo Rulli making a string of fine saves to thwart Gareth Bale in particular.
Luis Suarez missed an early penalty for Diego Simeone’s side but goals from Angel Correa and Matheus Cunha had them moving towards a regulation victory in the first half. However, in an incredible 12-minute sequence, Borja Mayoral got one back before Enes Unal scored a couple of penalties that put Getafe 3-2 up.
In first-half stoppage-time, Correa got his second of the game, yet Felipe’s red card before an hour was up gave the visitors the momentum once more. However, Mario Hermoso struck in the last minute to settle a game that almost literally had everything.
Osasuna, meanwhile, claimed a battle of two mid-table sides as they defeated the hopelessly out-of-form Rayo Vallecano 3-0 away from home. Jon Moncayola, Ruben Garcia and Kike Garcia were all on target in a game with a more one-sided result than the reality of the fixture.
In Saturday’s other game, Cadiz and Celta Vigo played out a scoreless draw.
LA LIGA STATISTICS: