Holders Real Madrid edged towards the last 16 of the Champions League, but disturbances between visiting Polish ultras and the police marred their 5-1 win at the Santiago Bernabeu on Tuesday.
Five fans and two police officers were treated for minor injuries after clashes outside the stadium before kick-off.
UEFA had already ordered the return match between the sides in two weeks' time be played behind closed doors due to violence and racist abuse in Legia's opening 6-0 defeat in Group F to Borussia Dortmund last month.
"Legia is a team with tradition and deserves to play in front of a full stadium," said Legia coach Jacek Magiera.
"These incidents reflect negatively on us and we have to ensure they don't happen again."
Once the action got underway, Madrid had way too much firepower as Gareth Bale, a Tomasz Jodlowiec own goal and Marco Asensio handed the hosts a comfortable half-time lead despite Miroslav Radovic's penalty.
Lucas Vazquez and Alvaro Morata came off the bench to round off the scoring after the break.
"I am happy with the result, the goals we scored and the chances we created," Madrid boss Zinedine Zidane told BeIN Sports.
Dortmund beat Sporting Lisbon 2-1 in the other game in the group, meaning Madrid and the Germans remain tied at the top of the pool on seven points.
Real and Dortmund will mathematically seal their place in the last 16 should they repeat their success over Legia and Sporting respectively on November 2.
Legia had shipped eight goals without reply on their return to the Champions League for the first time in 21 years before arriving in Madrid.
"After 21 years we have our first Champions League goal we're very happy about it," added Magiera.
Yet, the Polish champions had a slew of chances to take a shock lead before Madrid got going.
Jodlowiec fired meekly at Keylor Navas before Vadis Odjidja-Ofoe hit the post.
"Our idea was to play with a lot of attacking players, we took some risks, but you can always improve, especially in the chances we gave them," added Zidane.
Bale eased Real's nerves when he cut inside onto his favoured left foot and curled into the far post for his first Champions League goal since December 2014.
Marcelo's effort from the edge of the area deflected off Jodlowiec to leave Arkadiusz Malarz in the Legia goal flummoxed four minutes later.
However, the hordes of bare-shirted visiting fans got the moment of glory they came for when Danilo dived in to give away a penalty seconds later and Radovic converted from the spot.
The hosts restored their two-goal advantage before the break as Cristiano Ronaldo unselfishly teed up Asensio to drive home on his Champions League debut.
In the midst of a seven-game run in 29 days, Madrid eased off after the break.
And it needed the energy of two substitutes to keep the scoreboard ticking over as Morata and Vazquez replaced Bale and James Rodriguez.
Morata's cross was smashed home on the volley by Vazquez for Madrid's fourth.
Ronaldo endured a rare night without a goal in the Champions League, but still played his part with another fine pass for Morata to slide home the fifth six minutes from time.