Zlatan Ibrahimovic’s wonderful 64th-minute opener came out of the blue and he was later replaced by Ronaldinho, who netted the second late on.
That left Milan on eight points in Group G, and Ajax’s 4-0 thumping at home to Real Madrid ensured the Rossoneri would qualify as runners-up to the Spaniards.
Cristiano Ronaldo struck a brace as Madrid guaranteed themselves a first-place finish in the group after seeing off the hosts at the Amsterdam ArenA.
Goals from Karim Benzema and Alvaro Arbeloa put Madrid in control and Ronaldo struck twice after the break, the second from the penalty spot.
Madrid finished the match with only nine men after Xabi Alonso and Sergio Ramos were sent off in the closing stages after picking second yellow cards for time-wasting.
Marseille cruised into the last 16 with a 3-0 victory over Spartak Moscow at the Luzhniki Stadium.
Mathieu Valbuena got Didier Deschamps’ men off to the perfect start with a fine opener inside 20 minutes, and further strikes by Loic Remy and Brandao after the break ensured OM the margin of victory they required to progress.
Roma captain Francesco Totti capped a magnificent comeback with a late penalty as the Italians stunned Bayern Munich 3-2 at the Stadio Olimpico in Group E.
Trailing 2-0 at half-time after Mario Gomez’s two goals, Marco Borriello hit the back of the net four minutes after the re-start before Daniele De Rossi equalised.
Totti then scored the winner from the penalty spot six minutes from time. The result puts Roma within touching distance of the next round as they sit three points clear of third-placed Basle. Bayern have already qualified as group winners.
Frederico Almerares scored the only goal to keep Basle’s hopes of qualification from Group E alive. Almerares netted after 14 minutes against bottom side Cluj, who rarely threatened the home goal at St Jakob Park.
Goals from Taras Stepanenko, Jadson and Eduardo virtually assured Shakhtar Donetsk’s progression to the last 16.