Louis Longridge fired Dunfermline to a second consecutive victory when he scored a penalty five minutes after stepping off the bench.
Longridge, who replaced Aidan Connolly after 66 minutes, wrong-footed Ross Doohan from the spot after Michael Rose had been adjudged to have handled a Ryan Williamson cross.
Early on, Ryan Blair and Bruce Anderson looked the likeliest for Dunfermline while Michael Moffat went close for Ayr.
The visitors were presented with an opening when home defenders Rose and Daniel Harvie clashed but Joe Thomson blasted the loose ball over, then Andy Murdoch’s close-range effort was smothered by Dunfermline keeper Ryan Scully. Opposite number Doohan then made a brilliant point-blank save to thwart Connolly.
The game’s telling moment came when Longridge rolled home the penalty which pulls Dunfermline further clearof the danger zone and keeps alive their hopes of the play-offs while Ayr fall further behind leaders Ross County.