Karim Benzema hit a hat-trick and Vinicius Jr also found the back of the net as Madrid recovered from a 2-1 half-time deficit.
Espanyol had taken the lead through Raul de Tomas, only for Yannick Carrasco to equalise 11 minutes from time.
Substitute Lemar then won the game deep into stoppages.
Maxi Gomez, an Aridane Hernandez own goal, Goncalo Guedes and Omar Alderete found the net.
Real Sociedad are only one point further back on nine points after two goals from Mikel Oyarzabal beat Cadiz 2-0.
The Basque side struck twice in the second half, with Dani Vivian and Inaki Williams on target on the 68th and 74th minute.
Both Barcelona and Sevilla had their matchday four fixtures rescheduled due to World Cup qualifiers that would have clashed with their fixtures. It means that Barca will have a double header of matches next week.
LA LIGA STATISTICS: