A late, late goal from Jude Bellingham has given Real Madrid a one-goal advantage going into their blockbuster second leg against Manchester City next week.
City's No.9, who hadn't scored in his previous four games against Madrid, held the ball up for Jack Grealish, who collected it and dinked the ball towards the onrushing Gvardiol.
Both clubs finished outside the top eight in the league phase of the new Champions League format and were forced into a play-off round to reach the last 16, where Celtic or Bayern Munich - who play their first leg on Wednesday - await.
Erling Haaland had given City the lead twice before equalisers from Kylian Mbappe and Brahim Diaz in this Champions League last-16 play-off.
Tuesday's first leg marked the fourth successive year in which City have met Madrid in the knockout stages, and the fifth time in six seasons.