Ayr moved six points clear at the top of the cinch Championship after a thrilling 3-2 win at bottom side Hamilton.
Dipo Akinyemi put the visitors in front after just three minutes when he latched on to a loose pass and fired a shot into the bottom corner.
Hamilton should have been level on 23 minutes when Jean-Pierre Tiehi smashed a shot from the edge of the area which hit the bar and appeared to bounce down over the line, but the referee waved play on.
The home side deservedly equalised early in the second half after Sean McGinty shoved Andy Winter in the back and Steve Lawson fired home the resulting penalty.
Akinyemi volleyed in his second of the game in the 69th minute to restore Ayr’s lead after chesting down Finn Ecrepont’s cross, only for Ecrepont to then score an unfortunate own goal as he diverted Michael Doyle’s cross into the net with 10 minutes remaining.
However, just two minutes later Dan O’Reilly was penalised for needlessly pulling back Alex Kirk and Ben Dempsey held his nerve to score the winner from the spot.