© Getty Images
Gareth Bale scored four times for the hosts, who actually trailed 2-1 with 12 minutes on the clock, but they recovered to become the first La Liga team to score 10 goals in a game since 1969.
A spectacular first period at the Bernabeu brought six goals, one of which was a penalty, and two red cards.
Danilo sent Real Madrid into a third-minute lead, but two goals in the space of two minutes from Antonio Amaya and Jozabed Sanchez saw Rafael Benitez's team fall 2-1 behind, stunning the home supporters in the process.
Rayo were wobbling in the minutes that followed and conceded an equaliser to Bale, before going down to nine men shortly before the 30-minute mark when Raul Baena picked up his second yellow for pulling Sergio Ramos to the ground inside the box.
Cristiano Ronaldo stepped up to convert the resulting penalty, before Bale made it 4-2 in the 41st minute ahead of a second period that promised more goals due to Rayo's willingness to still commit players forward.
© Getty Images
Bale completed his hat-trick just past the hour when he converted a low cross from Ronaldo, with Real Madrid leading 7-2 with still 30 minutes of the league clash to play in the capital.
Bale was not finished and had his fourth in the 70th minute after playing a one-two with Rayo defender Quini, and the hosts had more goals in them as Benzema collected a Luka Modric pass before finishing for 9-2 with still 10 minutes remaining.
Benzema completed his hat-trick in the final minute to move Benitez's side into double figures for the afternoon, but they remain third in the table behind both Atletico Madrid and Barcelona. Rayo, meanwhile, are still in the bottom three.