Legia impressed for long spells against the 11-time European Cup winners, but it proved to be a routine victory for the home side, who are level on points with Borussia Dortmund at the top of the section.
As expected, it was Real Madrid that took control of the possession in the early exchanges, with Cristiano Ronaldo having the chance to strike a long-range free kick inside the opening five minutes, before the Portuguese had a low strike deflected wide of the post.
Legia did manage a shot on target in the seventh minute when Thibault Moulin struck one from distance, but it was comfortable for Keylor Navas and Real Madrid had another opportunity on the resulting break - Gareth Bale placing a Ronaldo cross wide of the post.
The best chance of the opening 10 minutes fell to the visitors though as Tomasz Jodlowiec broke into the Real Madrid box, only to see his low attempt saved by Navas. Two minutes later, Legia came even closer as a low strike from Belgian Vadis Odjidja from inside the Real Madrid box struck the outside of the post.
It was Real Madrid that made the breakthrough in the 16th minute, however, when Bale drove down the right before cutting inside and placing a low-footed strike past Arkadiusz Malarz into the far corner of the net.
The hosts scored their second in the 20th minute when Marcelo's low strike deflected off Jodlowiec before dropping into the back of the net, but Legia had one back less than two minutes later when Miroslav Radovic, having been fouled by Danilo inside the penalty box, stepped up to beat Navas from the spot to cap a crazy few minutes.
Karim Benzema, Marco Asensio and Ronaldo all came close to scoring a third for Real Madrid in the 10-minute period that followed, but Legia managed to keep the score down in addition to providing a constant threat on the counter-attack.
The hosts did manage to find a third in the 37th minute, however, when Asensio side-footed the ball home from inside the Legia box after a smart pick out from Ronaldo, flicking the ball back to the midfielder on his Champions League debut.
Real Madrid came close to a fourth goal early in the second period when Benzema lashed the ball towards goal after a Marcelo effort bounced into the striker's path, but Malarz was on hand to make a reaction save.
Legia continued to cause problems down the other end, however, and Guilherme had a penalty shout in the 54th minute, before the lively Odjidja missed the target with a curling effort from outside the home side's penalty box.
Los Blancos boss Zinedine Zidane made a double change just past the hour as Lucas Vazquez and Alvaro Morata replaced James Rodriguez and Bale in a bid to liven up what was a fairly quiet period of the match in the Spanish capital.
The double change worked as in the 68th minute, Morata delivered a cross onto the boot of Vazquez, whose thunderbolt of a volley ensured that Real Madrid could enjoy the final 20 minutes against the Polish champions.
Ronaldo came close to registering 10 minutes from time after a smart cross from Benzema found the Portugal captain, but his effort was wide of the post on what was another frustrating night for the 31-year-old, who missed an even better opportunity from close range in the 83rd minute.
Ronaldo, who had two more chances late on, did provide his second assist of the night in the 84th minute, however, as he set up the impressive Morata for Real Madrid's fifth and final goal at the Bernabeu.
Next up for Real Madrid is a home league match against Athletic Bilbao this weekend, while Legia will attempt to return to winning ways in their domestic division when they host Lech Poznan on Saturday.