Barcelona's 3-0 victory over Sevilla at Camp Nou had seen the Catalan giants move to the summit, but Real Madrid's success at the Estadio Municipal de Butarque ensured that they would top the table by two points.
Real Madrid boss Zinedine Zidane made nine changes to the team that started against Alaves at the weekend, with the likes of Cristiano Ronaldo, Gareth Bale, Toni Kroos and Karim Benzema all dropping out.
Alvaro Morata, Lucas Vazquez and Marco Asensio started as the front three, while there were also spots for Mateo Kovacic and James Rodriguez as Zidane shuffled his back during a busy run of fixtures for the Madrid giants.
As for Leganes, Luciano Neves and Unai Bustinza were among those handed starts against Los Blancos, but Alexander Szymanowski kept his spot in the team after netting against Real Sociedad last time out.
It was Szymanowski that had the first half-chance of the match in the third minute when the number 11 broke into the Real Madrid box, but his effort was blocked by Nacho and moments later, Los Blancos had a super chance down the other end.
It was Morata's own work which brought a clear opportunity for the Spain international, but the forward, who had replaced Benzema in the XI, could only send his effort wide of Iago Herrerin's post as both teams threatened in the early exchanges of the contest.
Luciano was next to come close for the home side after trying his luck from distance in the 11th minute, but the Brazilian's effort was wide of the post as the end-to-end nature of the match continued.
Real Madrid ultimately made the breakthrough in the 15th minute when James converted from close range after Asensio had used his pace to drive away from the Leganes defence and pick out the Colombian international, who simply could not miss from inside the penalty box.
Danilo hit the outside of the post in the 17th minute as Leganes survived another dangerous moment, but Real Madrid had their second from the resulting corner as Morata headed home at the far post after some lacklustre marking from the home side.
Two then became three in the 23rd minute when Mateo Kovacic released Morata with a cute pass, and the Spaniard swept the ball into the top corner to double his tally for the night, seemingly ending the game as a contest just past the mid-point of the first period.
Tito had the chance to give the home supporters something to cheer in the 28th minute when he broke into the Real Madrid box, but the full-back missed Keylor Navas's crossbar with his powerful strike.
Incredibly, the home side then made it 3-2 in the 34th minute when Luciano turned home from close range after meeting a flick from skipper Martin Mantovani, who had climbed highest to meet a corner from the left.
Real Madrid came close to scoring their fourth of the night late in the first period when Marcelo picked out Vazquez with a super cross from the left, but the Spaniard was denied by the outstretched arm of Herrerin.
Los Blancos had their fourth early in the second half, however, when Mantovani headed a James free kick into his own net under pressure from Morata, who initially appeared to have completed his hat-trick by getting the final touch.
Second-half substitute Samuel Garcia came close to making it 4-3 in the 55th minute after curling one towards the top corner following a sharp passing move from the home side, but his effort moved wide of the post, before Gabriel sent a 25-yard free kick into the stands.
Luciano was next to try his luck for Leganes 20 minutes from time, but the Brazilian missed the post from just outside the Real Madrid box during a period where both teams were struggling to carve out clear opportunities.
Luciano again came close to meeting a cross from Szymanowski late on as the pressure continued, but Real Madrid were ultimately comfortable as they eased their way to all three points, which ensured that they would top the table once again following a brief absence.
The final chance of the night came to Vazquez in the 89th minute when the Spaniard pounced on a poor header from Herrerin, but the Leganes goalkeeper made amends with a wonderful save.
Next up for Real Madrid is a home game against capital rivals Atletico Madrid on Saturday afternoon, while Leganes will attempt to return to winning ways when they travel to basement side Osasuna on Sunday night.