The hosts took the lead when Chris Duggan netted his tenth goal of the season after a cutback from Aaron Dunsmore. Lawrence Shankland had a chance to equalise before half-time but could not keep his shot down.
Michael Rose was more accurate in the 57th minute when he steered a header into the net from a corner to pull Ayr level and he then put his side in front with another header after 72 minutes. Craig Moore made it 3-1 two minutes later and Shankland added the fourth – Ayr’s 50th in the league – with a long-range effort late on.
Meanwhile, Queen’s Park and Airdrie shared a 1-1 draw at Hampden. The hosts wasted a good chance to take the lead when they were awarded a penalty but Luke Donnelly’s tame effort was saved by Rohan Ferguson.
Airdrie made them pay for the miss almost immediately when Luke Watt put them in front.
But the Glasgow side were level seven minutes from the break when Adam Cummins headed in a corner from David Galt.
Stranraer sank Forfar Athletic 3-0 at Stair Park to move third. Jamie Hamill failed to score from the penalty spot early on before Lewis Milne should have put Forfar in front midway through the first half but blasted his shot high over the top.
Ryan Wallace fired Stranraer into the lead with a penalty early in the second half after he had been brought down in the area and Angus Beith netted a late double.