Ayr twice came from behind to edge out Alloa in a seven-goal treat at rain-lashed Somerset Park, but the visitors blew a late chance for the equaliser when they failed with a penalty.
Alloa raced ahead in the 15th minute when Christopher Townsley nodded home from two yards after a curling cross from Stuart Callaghan.
Ayr took only six minutes to reply when Mark Smyth cracked home a low angled drive from 12 yards after good work from Paddy Connolly.
The visitors went back in front two minutes after the interval when home keeper Peter Cherrie missed a corner from James Stevenson and John Ovenstone scored with a free header.
A blunder by Alloa keeper Gary McGlynn allowed Ayr to draw level on 55 minutes. The youngster fumbled a Stewart Kean header into his own net to gift Ayr the equaliser.
McGlynn was immediately replaced by James Evans, but Ayr cashed in with two goals in four minutes from Connolly and Kean to take charge.
Alloa were reeling, but they gave themselves hope on 74 minutes when Andy Brown nodded home a cross from Richard Walker to cut the deficit to one goal.
Alloa then had a chance to snatch a point, when a Brown shot was handled by Tommy Tait, but Callaghan's penalty was superbly saved by the diving Cherrie at full stretch.