A six-goal thriller at Balmoor Stadium ensured both sets of fans went home entertained.
Peterhead took an 18th minute lead, Chris Hegarty set up the goal with a superb pass and Jamie Buchan finished with a shot across goal and into the net at the back post taking a slight deflection on the way.
Ayr should have levelled six minutes later, Mark Perry was harshly adjudged to have handled in the area but Jerome Vareille saw his spot-kick saved by home keeper Paul Mathers diving to his right.
United took the game to Peterhead from the restart and equalised after 48 minutes. Peterhead defender Calvin Shand headed the ball down instead of away from goal and Vareille pounced to score at the back post.
Peterhead were back in front in the 54th minute, following a superb solo run from Bobby Linn, who cut in from the left after being sent clear and struck a shot low into the net.
Ayr drew level again in the 72nd minute, Vareille casually sweeping the ball into the net from 18 yards with a well-placed first-time shot.
The visitors took the lead for the first time with a stunning strike from Ray Logan 11 minutes from the end following a free-kick.
Just when it looked like ending with an away win, Linn took a pass from Dougie Cameron to calmly net from the edge of the six-yard box for a share of the points.