Barcelona were dominant in every aspect of the game and took advantage of three mistakes by Real Madrid to score.
Barcelona dominated the match with almost 70 per cent of possession and 18 goal attempts to two for Rayo.
Lewandowski, who had 12 months remaining on his Bayern contract, moved to Barcelona in a deal worth 45 million euros and has joined the team on their US pre-season tour.
A sold-out Santiago Bernabeu stadium watched silently as a much-improved Barca under the command of new coach Xavi Hernandez dominated from the start.
Xavi probably could not have asked for much more in his first game managing a struggling Barca team who are sixth in the standings, eight points behind leaders Sevilla.
After the presentation Xavi talked about how discipline will be a major factor in his project as Barcelona manager.
The La Liga club received the green light on Friday to sign the 41-year-old after they paid the release clause in his contract with Qatari side Al Sadd.
Xavi is set to replace caretaker coach Sergi Barjuan who was appointed after the club sacked Koeman.
Koeman was sacked after Barca's 1-0 loss to Rayo Vallecano on Wednesday, their fourth defeat in six games in all competitions.
Local media reports suggest that former midfielder Xavi Hernandez, who is currently in charge of Al Sadd in Qatar, and Belgium coach Roberto Martinez are the frontrunners for the role.