The win may not have been the most comprehensive but was enough for Jimmy Calderwood's men to avoid a shock at Somerset Park and head back to the Granite City with their pride intact.
On paper, this was a tie Aberdeen should have cruised through despite being without skipper Scott Severin and Zander Diamond through injury and the suspended Lee Miller.
But Ayr had plenty of reasons of their own to be confident. For a start, their impressive form saw them top the Irn-Bru Second Division heading into the second round tie.
More importantly, Aberdeen's own form in the cup competitions had been far from convincing, suffering a shock defeat to Queen's Park in this tournament two years ago, before being dumped out of the Scottish Cup by Queen of the South last season.
The Pittodrie side could have knocked the stuffing out of their hosts early on when Jamie Smith's corner found the head of Derek Young, who glanced across goal and wide when he really should have left the net bulging.
Ayr then had a decent chance of their own when Maguire lost possession in the middle of the park, allowing Ryan Stevenson to embark on a run into the box. But finishing let him down and he dragged the ball harmlessly wide with Bertrand Bossu untroubled in the Dons goal.
Aberdeen pushed forward and another Smith corner broke to Gary McDonald. He supplied the cross from the right for Andrew Considine but his header was easily dealt with by goalkeeper Stephen Grindlay.
Young then resorted to blasting over from 40 yards, before Maguire finally opened the scoring five minutes from the break.
Charlie Mulgrew supplied a curling ball from the left and Maguire beat Grindlay to the ball to stab home from a few yards, with Ayr boss Brian Reid facing the task of lifting his players at the interval.
That is exactly what he did and the plucky lower league side started the second half well and could have been back on level terms had Martyn Campbell been able to take advantage of poor defending to bundle home from Stevenson's corner.
Aberdeen should then have killed the tie off as a contest with a lovely passing move which saw Darren Mackie set up Smith, only for his angled drive across the face of goal to smack off the post instead.
Ayr had one final go at forcing their way back into the tie when former Dons player Bryan Prunty tried his luck with a long-range volley which was comfortably gathered by Bossu as the SPL side held on for the win.