The two teams almost ran to a draw before Marco Asensio rose to save Real's blushes thanks to his 90th-minute golazo, scoring with only his side's third shot on target.
Leganes will travel to Spain's capital for the second-leg meeting at the Bernabeu on Jan. 24.
Just as he did for the round-of-16 run-in with second-tier Numancia, Real manager Zinedine Zidane made changes for Thursday's first leg and handed starts to a host of less-familiar faces.
Dani Ceballos and Marcos Llorente slotted into midfield, while Jesus Vallejo and Theo Hernandez came in at centre-back and left-back, respectively, and Borja Mayoral made his seventh start of the season in attack.
There was early heartbreak for defensive star Vallejo, however, after he had to come off with what appeared to be a hamstring injury, and La Liga writer Simon Harrison bemoaned his lack of match fitness:
Los Merengues struggled to engineer chances in the last round against Numancia, and the same could be said for Thursday's clash at Leganes, who came into this meeting with only two wins from their last six league games—the same record as Real.
A drab first half ended without much in terms of goalmouth action, and ESPN FC's Dermot Corrigan summarised an uneventful 45 minutes:
This was Real's first meeting of the season with Leganes as the pair have yet to face off in La Liga action, but the tame form shown by Zidane's reserves was somewhat familiar.
If it wasn't for a last-minute dash of goals in their first-leg meeting with Numancia, Los Blancos may not still be competing in this season's Copa del Rey, and yet still there was a sense of urgency lacking in their play.
Nabil El Zhar looked like the biggest threat from either team for long stretches of the match, although Hernandez handled the Moroccan winger's challenge well for the most part.
Nacho was fortunate to escape punishment when he bundled into the winger near halfway, although the officials failed to award even a yellow card for the incident.
As the pressure mounted for Zidane, he brought on the more senior creative personnel in Luka Modric and Isco with less than 30 minutes remaining.
However, it was starter Asensio who timed his eighth goal of the season to perfection, running in to poke home Hernandez's cross in the last minute of normal time, per the Guardian's Sid Lowe:
Again, Real left it late to decide the outcome of another Copa clash, but Zidane's second-string selection nevertheless brought home the goods.
We can undoubtedly expect a stronger XI to turn out for Wednesday's second leg, and Leganes will rue this result as a denied opportunity to give themselves the best possible chance at making the semi-finals.