Dale Hilson netted twice after Jamie McCluskey scored in the second minute. Omar Kader was also on target. Ayr, still in the play-off mix, hit back with a Michael Moffat penalty and a late Brian Gilmour strike.
Stenhousemuir must also sweat it out on the final day for a play-off spot after losing 2-1 at home to Airdrieonians.
The Lanarkshire side led at half-time after Scott Stewart netted on 28 minutes. Craig Barr put Airdrie further ahead in the second half. Sean Dickson pulled a goal back soon afterwards.
The bottom two both lost. Dunfermline Athletic beat Arbroath 2-1. Ryan Thomson headed Dunfermline in front after 14 minutes. Arbroath equalised after 55 minutes when Michael Travis headed home, but Dunfermline clinched it when Andy Geggan got on the end of a Danny Grainger cross.
East Fife lost 2-1 to Brechin City at New Bayview. Andy Jackson put Brechin ahead after 20 minutes. Alan Trouten made sure of the win with a late goal before Pat Clarke scored a consolation.