The match was played in sweltering conditions -- 32 degrees Celsius heat and relative humidity of 60 per cent -- which saw the game stopped for regular water breaks and multiple substitutions.
The shoot-out followed a 0-0 stalemate after 90 minutes and sealed victory for Real Madrid in the China edition of the International Champions Cup.
Both teams' goalkeepers ended up having to take a spot-kick with the score still tied after all outfield players had taken a turn.
Madrid goalkeeper Kiko Casilla confidently strode to the penalty spot before hammering the ball past Milan teenager Antonio Donnarumma to put his side 10-9 ahead.
The keepers then swapped positions with Donnarumma needing to score to keep AC Milan in the game, but the young Italian fired directly at Casilla who saved easily to seal victory for the Spanish club.
The dramatic climax was the highlight of an otherwise disappointing match in which neither side came close to scoring from free play.
Both clubs fielded strong line-ups -- Real Madrid started with the world's two most expensive footballers in Cristiano Ronaldo and Gareth Bale -- but despite the talent on display there was little notable action for the near-capacity crowd at the 60,000-seat Shanghai Stadium
Real Madrid had on Monday sealed a comprehensive 3-0 win over Inter Milan in Guangzhou, while on Saturday AC Milan beat city rivals Inter Milan 1-0 in Shenzhen