The pressure was on Los Blancos following a poor start to 2019, which had seen them take just one point from their two La Liga matches.
Leganes knocked Madrid out of the Copa del Rey last season, but the European champions have a three-goal lead to take into the second leg of this tie courtesy of Sergio Ramos's 100th goal in professional football and a second-half efforts from Lucas Vazquez and Vinicius Junior.
It took until the 11th minute for either side to register a shot - Dani Ceballos was the player who tried his luck from distance, but it was a comfortable save for Ivan Cuellar between the Leganes sticks.
Cuellar had to make another stop to keep out a header from Karim Benzema in the 15th minute, before the French striker missed the crossbar with effort from a dangerous position moments later.
Madrid made most of the early running in front of their own supporters. The atmosphere was fairly flat, however, and Leganes were having their moments as the first period progressed.
Indeed, Martin Braithwaite - making his debut following a loan move from Middlesbrough - headed into the arms of Real goalkeeper Keylor Navas, moments before the attacker just missed a low cross from Gerard Gumbau.
The home side had a decent penalty shout in the 25th minute when Alvaro Odriozola went down inside the box under a challenge from Rodrigo Tarin, but play continued, much to the disbelief of the Madrid defender.
Moments later, Leganes had a golden chance to take the lead when Braithwaite broke into a shooting position, but the attacker sent his low effort just wide of Navas's post.
Leganes' new forward had another opportunity in the 37th minute when he angled a header towards the back of the net, only for Navas to fly across his goal and make a super save.
Madrid did enter the half-time interval with an advantage, however, with Ramos converting from the penalty spot in the 44th minute after Gumbau had clumsily brought Odriozola to the deck.
There did appear to be more intensity to Real's work at the start of the second period, with an early strike from Ceballos showing the home side's intent.
Leganes goalkeeper Cuellar had to keep out a low strike from Reguilon in the 48th minute as Madrid continued to press forward. Vinicius was showing his class out wide, while Ceballos was busy in the middle of the park.
Federico Valverde also grew into the contest and the midfielder sent a powerful attempt over the crossbar in the 55th minute during a strong spell for the European champions.
Vinicius curled just wide of the Leganes post in the 58th minute, but Madrid had their second 11 minutes later when a mistake from the away side led to Vinicius squaring for Vazquez, who simply could not pass up the opportunity to double his team's lead.
Vinicius then got in on the scoring act in the 77th minute when he sent a wonderful volley into the back of the net having improvised to meet a cross from the impressive Odriozola.
Recent arrival from Manchester City Brahim Diaz came off the Madrid bench for his debut in the 78th minute, but the next opportunity of the match fell to the visitors - Braithwaite bringing another smart save from Navas.
Both teams had half-chances to add to the scoring in the latter stages, but 3-0 was how it finished as Madrid took a huge step towards the quarter-finals of this season's Copa del Rey.
REAL MADRID (4-3-3): Navas; Odriozola, Nacho, Ramos, Reguilon; Ceballos, Casemiro, Valverde; Vazquez (Isco 71'), Benzema (Gonzalez 83'), Vinicius (Diaz 78')
LEGANES (3-4-3): Cuellar; Bustinza, Tarin, Siovas; Juanfran (Jose 78'), Perez, Recio, Gumbau (Silva 46'); El Zhar (Eraso 63'); Sabin, Braithwaite