Barcelona, in their first match since Pep Guardiola announced he would quit at the end of the season, produced a sensational attacking display of their own to help ease a little of the pain suffered by their midweek Champions League exit to Chelsea.
Lionel Messi put Barca ahead and then an own goal from Rober' Correa who turned in an Alexis Sanchez shot, and a Seydou Keita strike gave them a 3-0 lead at the interval.
Pedro Rodriguez got a double in the second half and Thiago Alcantara was also on target before a minute from the end Messi got his second.
It means that Messi is now joint top scorer in the league with Ronaldo on 43 goals.
It was an unfamiliar looking Barcelona side that faced Rayo with Xavi Hernandez and Gerard Pique joining the injured while Guardiola chose to give reserve keeper Jose Pinto and youngster Martin Montoya a run out.
Although they lacked fluidity in the middle of the pitch to begin with they maintained their deadly attacking threat and Messi put them in front with 15 minutes gone after he was unselfishly played in by Pedro in front of goal.
Messi then found Alexis who rounded the keeper and his shot from a tight angle went in off Rober after 26 minutes, while Keita rounded off a fine move to give Barca a three-goal lead before the break.
Messi went past two defenders before nutmegging a third with a pass for Keita to score.
With a minute gone of the second half Pedro added the fourth, knocking in a rebound after Messi's shot had hit the crossbar and then 13 minutes from the end Thiago headed home but there was still time for further goals from Pedro and Messi.