Perterhead came from behind to keep their promotion dream alive as Ayr sank to their fourth defeat in a row.
Things looked bright for United after they surged into a fifth minute lead through Chris Roberston's goal, but they weren't in front for long
The visitors levelled just 10 minutes later after great work from Martin Wood set up partner Bobby Linn to fire home from the edge of the box.
United had the better of the play and pushed forward without creating many chances. They were punished midway through the second half when Grahem Sharp rounded the Ayr keeper to score the winner.
Ayr threw on top scorer Gareth Wardlaw from the bench, but they still struggled to create chances in the closing stages.
It was Peterhead who came closest to adding to their tally when Sharp and Douglas Cameron both had late shots tipped over.
Perterhead assistant boss Paul Mathers said: "We are third in the current table over the last 10 games and we now believe that third place overall is attainable rather than just going for fourth."
Disappointed Ayr boss Robert Connor said:"I am encouraged by results this week, and if we had a better quality of delivery into the box we would have created more chances."