After a cagey opening it was Vallecano who broke the deadlock on 11 minutes when Leonardo Carrilho's header was adjudged to have crossed the line. However, Espanyol could count themselves hard done by.
Joan Verdu shot just wide for the home side after 21 minutes as Espanyol looked to take control.
They were level after 37 minutes and it was Verdu again causing the trouble. His chip from close range on this occasion beat Andrade in the Vallecano goal.
Victor Sanchez shot wide just before half-time but Espanyol didn't have to wait long to take the lead. On 48 minutes Verdu scored from a corner to put the hosts 2-1 up.
Verdu could have had his hat-trick after 56 minutes, but this time put the chance wide of the target.
Instead, it was Vallecano who equalised in the 63rd minute through Carrilho's second goal. This time his finish from Alejandro Dominguez's cross was over the line.
Five minutes later, the away side were down to 10 men when Mikel Labaka was shown a straight red card.
Espanyol went forward looking for the winner, but with 10 minutes to play Vallecano's defence was holding firm.
Verdu turned provider deep in stoppage time, setting up Christian Stuani for a last-gasp winner for the hosts.