The Madrid suburbs club could have gone up last weekend but fell short, eventually sealing promotion on the last day of the season by finishing ahead of the already-up Real Valladolid.
Former Brazil great Ronaldo's side Valladolid, which he is a majority shareholder in, lost 2-1 at Tenerife allowing Leganes to finish top.
Eibar, Espanyol, Sporting Gijon and Real Oviedo finished between third and sixth and will compete in the play-offs for the final promotion spot later in June.