It was the home side who started the stronger and Philippe Coutinho so nearly opened the scoring after 11 minutes, but he fired wide.
Kalu Uche was next to come close for Espanyol after 19 minutes, but he fired wide when he might have done better.
The home side took the lead, however, after 24 minutes when Coutinho fired a powerful free kick into the top corner.
Malaga struggled to create any clear chances in the opening period, but Enzo Maresca struck the post with a header ten minutes before the interval.
Uche might have extended Espanyol's lead moments into the second period, but his shot from outside the area drifted wide.
Malaga so nearly brought themselves level courtesy of Santiago Cazorla after 50 minutes, but he shot wide.
Malaga did level the match after 76 minutes when Ruud Van Nistelrooy found the bottom corner with a cool finish.
There was to be one last chance, however, and Martin Demichelis added the away side's winner after 78 minutes to boost their top four hopes.