Leganes moved three points clear of the LaLiga relegation zone after edging to a 2-1 victory at fellow strugglers Rayo Vallecano despite finishing the fixture with 10 men.
On-loan Middlesbrough striker Martin Braithwaite opened the scoring after 36 minutes when he headed home from Jonathan Silva's corner but Leganes' hopes of holding on took a knock when Allan Nyom was dismissed.
The full-back, on loan from West Brom, saw red following a reckless challenge on Adrian Embarba just before the hour.
It seemed the man advantage played into Vallecano's hands as Alvaro Garcia netted on the rebound in the 83rd minute after fellow substitute Jose Pozo's initial shot had been saved.
But the hosts were level for barely two minutes before they conceded again, Youssef En-Nesyri heading beyond Stole Dimitrievski from Oscar Rodriguez's corner.
It proved the decisive act of a feisty contest, in which 10 players were booked.
Defeat for 18th-placed Vallecano ended their impressive unbeaten run, having won four of their previous five fixtures, and they are now one point adrift of safety.
ga('create', 'UA-72310761-1', 'auto', {'name': 'pacontentapi'});
ga('pacontentapi.set', 'referrer', location.origin);
ga('pacontentapi.set', 'dimension1', 'By Press Association Sport staff');
ga('pacontentapi.set', 'dimension2', '98c8cae8-70b6-477d-a906-a0a3e6d2b0b3');
ga('pacontentapi.set', 'dimension3', 'paservice:sport,paservice:sport:football,paservice:sport:match-reports,paservice:sport:uk,paservice:sport:world');
ga('pacontentapi.set', 'dimension6', 'story');
ga('pacontentapi.set', 'dimension7', 'composite');
ga('pacontentapi.set', 'dimension8', null);
ga('pacontentapi.set', 'dimension9', 'sport:football');
ga('pacontentapi.send', 'pageview', { 'location': location.href, 'page': (location.pathname + location.search + location.hash), 'title': '10-man Leganes beat relegation rivals Rayo Vallecano'});