A header from Michael Donald proved the difference for Ayr, as they held on to win 2-1 against Forfar at Somerset Park.
The Honest Men had managed just two wins from their last 12 matches, but victory sees them pull away from the relegation play-off place and move to within three points of fifth-place Forfar.
Ayr striker Liam Buchanan slotted home from six yards after 19 minutes to give Mark Robert's men the lead against Dick Campbell's side, who have now lost five of their last six matches.
The Loons had a great chance to equalise after 65 minutes, but Michael Bolochoweckji's header was saved by Ayr goalkeeper Graeme Smith, and the side with the league's worst defensive record were made to rue their missed opportunity minutes later.
A cross from the right wing by goalscorer Buchanan found Donald in the centre of the penalty area and his header nestled into the bottom-right corner to give the hosts a two-goal lead.
Forfar were given a lifeline after 74 minutes when Iain Campbell converted a penalty following a foul by Christopher Smith, but Ayr hung on to claim a vital three points.