Chris Smith was Ayr United's matchwinner for the second game running as Brian Reid's side came from two goals down to beat Hamilton.
The hosts took the lead from the penalty spot on 17 minutes, Paul Currie converting after Smith had fouled Matthew Paterson.
Greig Spence's header just on half-time doubled Hamilton's lead.
Michael Moffat swept home to bring Ayr back into the match on 52 minutes.
John Robertson then levelled with a close-range finish from Micheal McGowan's free kick.
Smith, who headed Ayr's winner against St Mirren in the Scottish Communities League Cup on Tuesday, nodded past David Hutton in injury-time to complete the dramatic comeback.
The win moves Ayr off the bottom of the First Division table.
Hamilton: Hutton, McAlister, Canning, McLaughlin (Anderson 58), Gillespie, Currie (Lyle 82), Mensing, Crawford (Chambers 73), Imrie, Paterson, Spence. Subs Not Used: Thomson, McBride.
Booked: Mensing, Gillespie.
Goals: Currie 17 pen, Spence 45.
Ayr: Cuthbert, Tiffoney, John Robertson, Smith, Malone, Trouten (McKernon 75), Geggan, Ross Robertson, McGowan, Wardlaw (Roberts 76), Moffat. Subs Not Used: McWilliams, Burke, Connolly.
Goals: Moffat 52, John Robertson 57, Smith 90.
Ref: David Somers