Karim Benzema scored twice in between goals from Gareth Bale and Sergio Ramos to secure the three points, despite a scare when Guido Carrillo made it 1-1 when he fired a penalty past debutant goalkeeper Thibaut Courtois.
The victory puts Julen Lopetegui's side top of the table, two points above Celta Vigo, who beat Atletico Madrid 2-0 at Balaidos.
Bale stretched his scoring run to seven consecutive league games 17 minutes in, volleying in Dani Carvajal's header from 12 yards out, although goalkeeper Ivan Cuellar should arguably have done better to keep it out.
Leganes went into the game having failed to win any of their 10 Madrid derbies in LaLiga, but they snatched an equaliser 24 minutes in when Carrillo swept home from the penalty spot after Casemiro tripped Javier Eraso.
The goal seemed to disrupt Madrid's rhythm, although they continued to have nearly 80 per cent of the possession, with Cuellar denying Benzema's volley in one of the few chances before half-time.
But Benzema put them back ahead three minutes after the break with a well-aimed header, the goal eventually given after a VAR review overturned a foul awarded against the striker.
There was no doubt about Benzema's second, though, as he collected Marcelo's pass, played a one-two with Luka Modric and rifled a shot into the bottom-left corner from the edge of the area.
Captain Ramos added a fourth from the penalty spot 66 minutes in to move the European champions onto nine points and send them into the international break in a positive mood.
What does it mean: Bale and Benzema showing there is no need for Ronaldo replacement
Mariano Diaz was not quite the new number seven Madrid fans had in mind after Cristiano Ronaldo joined Juventus, but the Portugal star will not be missed too much if Bale and Benzema can continue this form.
Bale is on his best goalscoring run ever in LaLiga and Benzema is looking as sharp as he has in the last three seasons. If the duo have been liberated by Ronaldo leaving the team, they are taking full advantage.
It is far too early to predict the title race's trajectory, but Madrid appear to be more readily equipped than Atletico Madrid to challenge Barcelona, even though only 16 days have passed since they lost the UEFA Super Cup to their city rivals.