A header from Michael Donald clinched the points for Ayr, as they held on to win against Forfar at Somerset Park.
The Honest Men had managed just two wins from their last 12 matches, but victory has pulled them away from the relegation play-off place and move to within three points of fifth-place Forfar.
Ayr went ahead when Liam Buchanan slotted home from six yards after 19 minutes.
Forfar had a great chance to equalise after 65 minutes, but Michael Bolochoweckji's header was saved by Graeme Smith, and the side with the league's worst defensive record were made to rue their missed opportunity.
A cross from the right wing by 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.
The visitors were given a lifeline when Iain Campbell converted a penalty following a foul by Christopher Smith, but Ayr hung on to claim a vital three points.
Ayr: Graeme Smith, McAusland, Christopher Smith, McGregor, McCann, Winters, Sinclair (Hunter 78), Crawford, Donald, Buchanan, Moffat. Subs Not Used: Brown, McStay, Wyllie, Roberts.
Booked: Moffat, McAusland, Winters.
Goals: Buchanan 19, Donald 69.
Forfar: Hill, McCulloch, Bolochoweckyj, Dunlop (Tulloch 29), Iain Campbell, Ross Campbell, Robertson (Malin 71), Brown (Denholm 46), Hilson, Templeman, Swankie. Subs Not Used: Salmon, Kader.
Booked: Ross Campbell, Swankie, Tulloch.
Goals: Iain Campbell 74 pen.
Ref: Iain Brines