Gabriel Jesus and Kevin de Bruyne gifted City the win after Isco opened the scoring for Real Madrid.
The first half was as close to a game of chess that a football game can be, with both sides taking no risks until Raphael Varane fired over the bar in the 16th minute.
Kevin de Bruyne fired wide for City, while Karim Benzema saw a header comfortably saved by Ederson shortly before Aymeric Laporte had to be replaced by Fernandinho due to injury.
The second half saw Manchester City look to take the game to Real Madrid, with Riyad Mahrez going close before seing a shot well saved by Thibaut Courtois, before Fernandinho fired wide after a corner.
However, Madrid took the lead just when City looked to be dominating. Vinicius Jr took advantage of a defensive error before passing for Isco to score with a diagonal shot.
In the 73rd minute, Raheem Sterling came on as a substitute for City and the game changed totally.
The English side equalized with a Gabriel Jesus header after a Kevin de Bruyne cross in the 78th minute, and five minutes later Sterling won a penalty after a wild challenge from Dani Carvajal.
City had missed their four previous spot kicks, but De Bruyne kept his cool to send his international team-mate Courtois the wrong way and make it 2-1 to the visitors.
Things got even worse for Madrid when Sergio Ramos was shown a direct red card for bringing down Gabriel Jesus when he was through on goal and the Madrid captain will miss the return leg.
City should have added to their lead, but first Sterling and then Mahrez wasted chances to make it 3-1.
END/AP/UNB/TZ