Karim Benzema’s hat-trick against Almeria saw him pass Hugo Sanchez as the fourth-highest scorer in La Liga history with 236 goals.
Benzema scored two close-range finishes after cutbacks from Brazil wingers Vinicius Junior and Rodrygo.
Lucas Vazquez was fouled by Largie Ramazani and Benzema converted from the spot to complete his first-half treble.
Victory sees second-placed Real Madrid move within eight points of leaders Barcelona.
Carlo Ancelotti’s side got back to winning ways before Real’s Champions League semi-final against Manchester City on 9 May.
Only Lionel Messi (474), Cristiano Ronaldo (311) and Zarra (252) have scored more goals in the Spanish top flight than the 35-year-old former France forward.
Almeria pulled a goal back in the dying seconds of the first half, with Ramazani atoning after conceding the penalty by crossing into the six-yard box for Lazaro Vinicius to finish.
Two minutes after the restart, Rodrygo fired a screamer into the top corner from outside the box.
Substitute Lucas Robertone headed in from a Francisco Portillo cross just after the hour mark as relegation-threatened Almeria put up a fight against the defending champions, but were ultimately overpowered.
Eduardo Camavinga and Rodrygo had diving headers ruled out for offside with Los Blancos unable to get their fifth goal of the thrilling contest.
Barcelona have the chance to restore their 11-point lead at the top when they face Real Betis this evening at 20:00 BST.