Steven Bell's knockout blow left Ross County with ringing in their ears as his goal sent Ayr into the fifth round of the William Hill Scottish Cup.
The midfielder was left unchallenged to nod Stephen Kelly's corner into the net and put the Honest Men into the hat for Sunday's draw.
The Ladbrokes Championship outfit soaked up early pressure, with Ross County creating most of the danger in the first half.
But the first real chance for County did not come for 20 minutes when Harry Paton sent a perfectly weighted ball for Lee Erwin who was onside and charged towards goal from 30 yards out. His low drive was well blocked by goalkeeper Ross Doohan.
Erwin came close a minute later when he managed to get a head on Blair Spittal's cross on the edge of the six-yard box but could not guide the ball on target.
Paton and Erwin continued to cause problems in the Ayr defence throughout the first half but Doohan was able to comfortably handle any danger which headed towards goal from either player.
Ayr were rewarded when they broke the deadlock nine minutes before half-time when Bell beat County's defence in the air to head Kelly's corner into the net from six yards out.
Ross County went close to levelling just before half-time when Erwin managed to get a shot on goal from the edge of the box but Doohan saved well.
Ross County started the second half brightly when Josh Mullin threatened after connecting with Spittal's cross, but again Doohan gathered comfortably.
Billy Mckay went close to levelling the scores when he beat the Ayr defence to Mullin's cross from 10 yards out but he nodded wide of the right post.
But Ayr held on to record a shock win and progress to the next round.