Brechin extended their lead at the top of the second division to nine points after Graham Gibson's late winner at Somerset Park.
Gibson turned to slam home a flick on from Paul Ritchie just as Ayr looked set to take a deserved point.
United had the better of a scrappy game and Stuart Boyd missed three good chances before Brechin struck.
Andy Ferguson also missed with two efforts as the leaders rode their luck.
Grant Johnson missed Brechin's best other chance when he skied a Ritchie cut back over the bar from 12 yards.
Boyd should have put Ayr ahead seconds before Brechin's winner, but he turned a shot wide from only three yards.