The first half saw Los Blancos enjoy the lion's share of possession against La Liga's 13th-placed side but the visitors only managed to produce three shots, none of which was on target.
Leganes were more ambitious in the second half and enjoyed several chances as Jose Naranjo and Claudio Beauvue forced smart stops from Kiko Casilla and Marcos Llorente headed against his own crossbar.
However, Real managed to contain their opponents and turned the screw late on in the game, which culminated in Asensio's late winner to give the reigning La Liga champions the upper hand ahead of the second leg at the Bernabeu on January 24.
LEGANES (4-2-3-1): Champagne; Tito, Bustinza, Siovas, Rico; Perez (Branasac 61') Gumbau; El Zhar, Eraso, Naranjo (Amrabat 70'); Beauvue (Omar 82')
REAL MADRID(4-3-3): Casilla; Carvajal, Varane, Vallejo (Nacho 15'), Hernandez; Kovacic, Llorente (Isco 73'), Ceballos (Modric 67'); Lucas, Mayoral, Asensio