Leganes were relegated from La Liga following a 2-2 draw with champions Real Madrid at Estadio Municipal de Butarque on the final day of the season.
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 Friday (AEST), went ahead through Sergio Ramos' early header before Bryan Gil equalised for the hosts.
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 La Liga ended in agonising circumstances.
What does it mean? Leganes fall just short of a great escape
Leganes had been in sensational form in their previous outings to give themselves a fighting chance of survival but, though they poured forward in the closing stages and came so close to securing a sensational win, it was not to be, with Madrid having enough quality to see out the draw.
Record-setting Ramos on target yet again
The Madrid icon has been a talismanic presence since the resumption of action last month, and the 34-year-old became the first defender to score over 10 La Liga goals in a season in the 21st century with his fine header in the opening stages.
Anguish for Aviles
Aviles will be haunted by his miss for a long time to come. He was given the space of the Madrid penalty area late on but skewed his shot wide. It proved to be the difference between survival and relegation.
Real Madrid have a Champions League campaign to resume, with the second leg of their last-16 tie against Manchester City at the Etihad Stadium on August 8. Leganes, meanwhile, will have to pick themselves up for a campaign in the second tier.