Stephen O’Donnell and Conrad Balatoni were on target for top flight Partick, although Mark Shankland’s late strike meant an uncomfortable final few minutes for the hosts who struck the woodwork twice.
After Craig Malcolm had missed an early close range header for the visitors, O’Donnell opened the scoring in the 12th minute.
From Christie Elliott’s assist, O’Donnell fired home from 25 yards.
Although Partick dominated possession for the remainder of the first half, it was Ayr who created the better chances with Malcolm coming close to an equaliser when he lobbed home keeper Scott Fox only to see the ball bounce off the bar.
Ayr continued to threaten after the break with Michael Moffat missing another chance to level the scores.
At the other end debutant Gabriel Piccolo headed against the bar, and seven minutes later the hosts doubled their advantage.
From a Steven Lawless cross, Balatoni heads home Partick’s second.
Balatoni almost added a third from John Baird’s corner but three minutes from time Shankland headed Ayr back into the cup tie.
And within 90 seconds of the goal, substitute Shankland almost netted again, this time being denied by the post – as Partick survived to reach the next round.