Carlos Bacca missed a one-on-one and in the shootout, as Milan went down to Real Madrid on penalties after a goalless draw.
Sinisa Mihajlovic fielded Alessio Cerci and M'Baye Niang up-front, with the Diavolo playing their second match in China after the win over Inter.
The French forward looked dangerous right away, pulling out a great piece of trickery on the left wing before his cross was snatched by Keylor Navas.
Cristiano Ronaldo was typically keen to shoot from any angle for Los Merengues, but his one effort on target was easily gathered by Diego Lopez.
Milan could have taken the lead on half-time when Niang nutmegged Pepe, but the striker saw his effort saved by Navas.
As is customary in pre-season friendlies, half-time saw a raft of changes, with the Rossoneri introducing much-heralded new strikeforce Carlos Bacca and Luiz Adriano.
Despite the changes, the biggest star of all remained on the pitch, and Ronaldo saw a header brilliantly saved by Diego Lopez on 57 minutes.
Bacca was denied a first goal for his new club with just over an hour played, Kiko Casilla diving to expertly block his right-footed effort.
The heat in Shanghai was so intense that a cooling break was required in either half, but the game was nevertheless played with intensity.
Colombian international Bacca had another good chance with 10 minutes remaining, pouncing on a Sergio Ramos mistake to go one-one-one with Casilla, but the ‘keeper stayed on his feet and the striker shot straight at him.
That meant the match would be decided on penalties, with Alessandro Matri replacing Philippe Mexes for the spot-kicks.
James Rodriguez converted Los Merengues first penalty with ease, while Casilla got close to Nigel De Jong's effort, but was unable to keep it out.
Marcelo, Matri and Casemiro also dispatched from 12 yards, but Bacca's bad day continued when he saw his attempt saved.
Sergio Ramos put Real Madrid into the lead, but Keisuke Honda kept Milan's hopes alive and 16-year-old Gianluigi Donnarumma showed why he's so highly thought-of by saving from Toni Kroos.
Luiz Adriano then took the shoot-out to a sudden death situation, where Dani Carvajal put the pressure back on the Rossoneri with a Panenka-style goal. Riccardo Montolivo levelled things up, but Nacho put the Spanish giants back in front.
Cristian Zapata, Denis Cheryshev, Jose Mauri Isco, Davide Calabria, Jese and Gabriel Paletta also made no mistake from the spot, meaning the goalkeepers would have to take a kick.
Casilla scored his effort, meaning the pressure was all on youngster Donnarumma, who missed his effort, handing the win to Real Madrid.
Real Madrid 0-0 Milan (Real Madrid win 10-9 on penalties)
Milan: Lopez (Donnarumma, 72); De Sciglio (Paletta, 72), Alex (Zapata, 45), Ely (Mexes, 45 Matri, 90+4), Antonelli (Calabria, 72); Poli (Mauri, 45), De Jong, Bertolacci (Montolivo, 45); Suso (Honda, 45) ; Niang (Luiz Adriano, 45), Cerci (Bacca, 45).
Real Madrid: Navas (Casilla, 45); Arbeloa (Marcelo, 72), Varane (Ramos, 45), Pepe (Nacho, 72), Danilo (Carvajal, 72); Casemiro (Kroos, 45), Modric (Isco, 45); Lucas, Ronaldo (James Rodriguez, 72), Bale (Cheryshev, 72); Benzema (Jese, 45)