Alan Forrest's last-gasp winner was enough for Ayr as they beat Queen's Park at Hampden.
Michael Moffat and Craig Malcolm both went close for the visitors in the opening stages but neither could find a way past Spiders stopper Michael Brown.
The hosts soon took control of the game and were ahead just before the half-hour mark.
Tony Quinn netted from the penalty spot after Martyn Campbell was judged to have handled the ball inside the area.
Bernard Coll could have added a second shortly after but blazed his effort wide after some good build-up play.
However, the Honest Men were level shortly after the restart when Moffat poked home Campbell's pass.
With the game seemingly heading for extra-time, substitute Forrest popped up a minute from time, finishing from close range after Adam Hunter's long throw caused problems in the area.