The top-flight side had the best of the chances and scraped through in the end thanks to a second half strike from McKenzie.
As well as progressing in the competition, the win allowed Killie to claim the bragging rights in this derby clash.
Kilmarnock named an unchanged side from the one who defeated Motherwell on Saturday.
Craig Slater started on the bench but Michael Ngoo was still absent from the squad after both had missed out with ankle knocks at the weekend.
Killie had started the season well but confidence was also high in the Ayr camp ahead of this clash, with three victories taking them to the top of League One.
It was the visitors who had the first real chance of the game after just four minutes when Nicky Devlin nodded just over at the back post under pressure from Manuel Pascali.
Devlin was cautioned for a foul on Chris Chantler and only the woodwork prevented Sammy Clingan from netting from the resultant free-kick, as his effort came off the crossbar.
The home side continued to press for the opener and Jamie Hamill teed up Pascali but his header was off target and dipped over the crossbar.
Tope Obadeyi then found himself through on goal but Devlin managed to intercept with a tackle that prevented the Killie man from having a clear shot at goal.
Obadeyi hobbled out of the action eight minutes before the break and was replaced by Alexei Eremenko as the first half ended goalless.
Killie still looked dangerous after the break and Josh Magennis volleyed over from 15 yards, before sending another effort across goal and wide of the upright.
The breakthrough eventually came after 69 minutes when Hamill picked out McKenzie and he left David Hutton helpless with a lovely volley.
Hopes of a late Ayr comeback could have been all but snuffed out had Magennis been able to find the back of the net with a powerful header Hutton did well to gather.
Eremenko then stung the palms of the keeper but Killie managed to hold on for the win and book their place in the next round.