Unai Bustinza gave the hosts a shock lead after just six minutes, profiting from some terrible defending.
The Brazilian midfielder created the 11th-minute equaliser as Spain winger Lucas Vazquez continued his impressive recent form and converted a glorious victor before the half hour.
The win lifts Zidane's side above Valencia and into third in the standings on 48 points after 24 games, 14 behind leaders Barcelona and seven behind second-placed Atletico Madrid.
And Bustinza won the duel to open the scoring with a "salmon header".
France's wardrobe malfunction ice skater bounces back to win silver
During the Winter Olympics 2018 French ice dancer Gabriella Papadakis suffered a wardrobe mishap during her performance . In the clip, you see 22-year-old Gabriella's green dress snap at the neck during the early stages of their dance.
Man Utd midfielder Matic: VAR only needs tweaking
But we are all in a learning process here and no-one should give up just yet on a system I have long supported. With that second goal in the second half I think we killed the game and from that moment we were in control.
Google AI looks at your eyes to predict heart disease risk
Deep learning applied to a retinal fundus image, a photograph that includes the blood vessels of the eye , can predict risk factors for heart diseases .
Madrid were comfortably on top as the half wound down, with Benzema nearly heading a third from Lucas' cross.
Leganes had more of the ball in the latter stages of the first period, but they went in behind as Real Madrid turned things around following a slow start in the Spanish capital.
Gareth Bale came off the Real Madrid bench in the 76th minute, but the Welshman's introduction did little to raise the tempo as both teams continued to struggle in the final third of the field.
The Wales worldwide nearly picked out the bottom corner after springing the offside trap, but it was Ramos who grasped the ball and made no mistake when Diego Rico bundled Kovacic to the floor.