Madrid already had the league title wrapped up heading to their city neighbours, but still claimed a point which proved enough to send Leganes down following a 2-2 draw.
Javier Aguirre's Leganes had won three of their previous four outings but, despite twice coming from behind, they failed to claim the win they needed to overtake Celta Vigo, who were held to a goalless draw by relegated Espanyol.
At the other end of Spain's top flight, Granada made a late charge for a place in the Europa League with a 4-0 victory over Athletic Club, who finished 11th.
Granada's triumph meant Getafe, who went down to a 109th-minute goal from Coke against Levante, dropped out of the top seven.
A 4-0 win over Eibar saw Villarreal consolidate their place in fifth, with the Yellow Submarine four points above Granada and Real Sociedad, who snatched a late 1-1 draw at Atletico Madrid to be sure of their European qualification.