Ross McMillan scored deep into stoppage time as Stenhousemuir rescued a point at Somerset Park.
The hosts took the lead in the 19th minute when David Winters collected Michael Moffat's pass before producing a neat finish inside the area.
And they could have been further ahead shortly after but for some good defending from Kevin McKinlay, who managed to block Mark Shankland's goal-bound effort.
The visitors' best chance fell to Andy Rodgers just before the interval but goalkeeper Alistair Brown was alert to produce a fine stop.
Stewart Kean almost scored the equaliser 10 minutes from time but Brown produced another excellent save to tip his shot round the post.
But Stenny were not to be denied and when Greg Ross swung a deep cross into the box in the final minute McMillan rose highest to head it into the corner.
Ayr: Alistair Brown, Hunter, John Robertson (Longridge 75), Martyn Campbell, Brownlie, Sinclair, Winters, McStay (Crawford 70), Moffat, Shankland (Roberts 59), Marenghi. Subs Not Used: Martin, Ross Robertson.
Goals: Winters 19.
Stenhousemuir: Reidford, Ross, McKinlay, Iain Thomson, McMillan, Hodge, Darren Smith, Rodgers (Brash 75), Kean, Craig Anderson, Dickson. Subs Not Used: Shaw, Lawson, Kieran Anderson, Love.
Booked: Darren Smith, Craig Anderson.
Goals: McMillan 90.
Ref: Stevie O'Reilly