Javier Aguirre's side had won three of the four games ahead of the visit of Los Blancos but ultimately fell short of the three points required to overhaul Celta Vigo, who drew 0-0 with Espanyol.
Madrid, who sealed their first title since 2017 with victory over Villarreal on Thursday, went ahead through Sergio Ramos' early header before Bryan Gil equalized for the hosts.
11 - @realmadriden's Sergio Ramos has scored 11 goals in @LaLigaEN 2019/20, the most by a defender in a single season in the 21st century (Mariano Pernía, 10 for Getafe in 2005/06). Captain. pic.twitter.com/POhxClToF2— OptaJose (@OptaJose) July 19, 2020
Roger Assale set up a grandstand finish following Marco Asensio's strike shortly after the interval, but Leganes were ultimately unable to find a precious winner, with Madrid surviving a late VAR check for a possible penalty.
Madrid looked lively in the opening stages, Federico Valverde forcing Ivan Cuellar into a superb save with a swerving effort from distance.
Their early dominance was rewarded after nine minutes – an unmarked Sergio Ramos heading home his 11th league goal of the campaign from Isco's free-kick.
Recio and Gil tested Alphonse Areola as the hosts responded well, and Leganes had their reward in stoppage time when Gil opened his account with a neat finish from an acute angle.
Leganes' hopes suffered a blow six minutes after the interval, though, with Asensio slotting past Cuellar after latching onto Isco's sublime pass.
Yet Leganes refused to go down without a fight and they drew level again 12 minutes from time when substitute Assale fired underneath Areola.
Javier Aviles inexplicably lashed wide from eight yards in the closing stages, while a lengthy VAR review into a potential handball from Luka Jovic gave Leganes hope of a dramatic penalty. Nothing was given, though, as their four-year stay in LaLiga ended in agonising circumstances.