All three goals came before half-time, with the Dons taking a third minute lead courtesy of an own goal.
Darryl Meggat was the unlucky player, turning a Wes Burns cross into his own net.
And it was 2-0 after half-an-hour as Niall McGinn volleyed home Shay Logan's cross.
The hosts reduced the arrears four minutes before the break when Alan Forest netted from close range.
In truth, Aberdeen should have added further goals, with Adam Rooney hitting a post and Wes Burns finding the crossbar twice.
And after beating Ayr in only their second meeting for 31 years, Dons were presented with a home quarter-final tie against St Johnstone.
Source: Sky Sports