Real Madrid struck late on to earn a 2-2 draw at AC Milan and secure a place in the Champions League knockout phase, where they were joined by Chelsea and Bayern Munich.

In Wednesday's matches, Chelsea won 4-1 at home to Spartak Moscow to go six points clear in Group F, while Bayern maintained their perfect record with a 4-0 win at CFR Cluj in Group E, but Arsenal fell to a 2-1 defeat at Shakhtar Donetsk.

Real's trip to Milan marked Jose Mourinho's first visit to the San Siro since he left Inter Milan after guiding them to last season's Champions League title, and his new side immediately established a firm grip on the game.

Angel di Maria shot wide after cutting in from the right, while Andrea Pirlo twice had to head the ball off the Milan goal-line, before Gonzalo Higuain broke the deadlock from Di Maria's cute pass on the stroke of half-time.

Real looked dominant, but in the 68th minute the hosts drew level when Iker Casillas palmed Zlatan Ibrahimovic's mis-hit cross into the air and substitute Filippo Inzaghi headed home from close range.

Inzaghi, a replacement for the disappointing Ronaldinho, put Milan ahead 10 minutes later, tucking away Gennaro Gattuso's through-ball for his 46th goal in the competition despite a strong suspicion of offside.

Real were on course for their first defeat under Mourinho, but in the fourth minute of injury time Pedro Leon converted a pass from fellow substitute Karim Benzema to snatch a share of the spoils.

"Their first goal came from a slip by Pepe and their second was clearly and obviously offside, without a shadow of doubt," Mourinho told Sky Sport.

"But I don't want to talk about Pepe or the referee. We played very well tonight and Leon's equaliser was deserved."

The result puts Real five points clear of Milan, who are now just two points ahead of Group G's bottom side Auxerre after the French team kept their hopes of a last-16 place alive with a 2-1 win at home to Ajax.

Chelsea joined Real in the next phase, but they had to wait until the second half before seeing off Spartak at Stamford Bridge.

Nicolas Anelka opened the scoring with a smart chipped finish in the 49th minute, before Didier Drogba marked his first start in the competition this season with a 62nd-minute penalty.

A brace from Branislav Ivanovic made sure of the points, with Nikita Bazhenov replying for the visitors.

"It was a good evening, we played well and we got a good result," said Chelsea coach Carlo Ancelotti. "Now we have to ensure we top the group."

Second-placed Spartak are now level on six points with Marseille, after Didier Deschamps's side belatedly hit form with a 7-0 thrashing of MSK Zilina -- a record for an away game in the competition.

Andre-Pierre Gignac claimed a hat-trick for the visitors, with Lucho Gonzalez netting a brace.

Arsenal took a 10th-minute lead through Theo Walcott in their Group H clash in Donetsk, but the hosts equalised when Dmytro Chygrynski's header glanced off Craig Eastmond for an own goal.

Gunners old boy Eduardo scored the winner just before the break, following an error from visiting left-back Gael Clichy, to draw the Ukrainians level on nine points with Arsenal at the group summit.

Arsenal coach Arsene Wenger told Sky Sports: "We had a good start but after that we eased off too much. We were punished against a good team. It's a good lesson for us."

Sporting Braga are three points back in third, after a 1-0 win at Partizan Belgrade that eliminated the Serbian side from the competition.

In-form German striker Mario Gomez grabbed a hat-trick as Bayern, last season's runners-up, routed Cluj 4-0 in Romania.

"Four-nil in the Champions League is a superb result," said Bayern captain Philipp Lahm. "After we took the lead early in the first half, it was relatively easy."

Roma survived a late fightback to win 3-2 at Basel, as Claudio Ranieri's side climbed from fourth to second in Group E.