The Buddies had the best of the chances in Paisley but it was the Irn-Bru First Division outfit who struck late on to remain in the tournament.
Ayr have now enjoyed a hat-trick of victories over SPL opposition in the competition so far, having also seen off Inverness and Hearts in previous rounds.
St Mirren manager Danny Lennon named an unchanged side, opting for the same group of players who narrowly lost to Hibernian at the weekend.
Ayr added Smith and Gareth Wardlaw to the starting line-up after losing to Dundee in their last outing.
Saints tried to put their opponents under pressure early on and David van Zanten was not too far away with a shot from inside the box that dipped just over the crossbar.
At the other end, Alan Trouten released Wardlaw into the box but his return pass was misplaced and allowed the home side to clear the danger with ease.
There was a nervous moment for Ayr when goalkeeper Kevin Cuthbert attempted to gather a cross from Jereon Tesselaar and spilled the ball with Steven Thompson loitering with intent, but Smith was alert and hooked to safety.
Steven Thompson then saw another opportunity squandered when he rose above everyone else in the packed goalmouth and nodded just over from a Kenny McLean corner.
Saints continued to pile on the pressure and an angled pass from Paul McGowan found Thomson for the header, with Cuthbert slipping before recovering to claw the effort past the upright.
McLean passed up a decent chance to open the scoring just after the restart when he met a Jim Goodwin cross and saw his header flash across the face of goal.
With the tie still deadlocked, Saints made their first change 11 minutes into the second half, with Nigel Hasselbaink thrown into the action for Thomson.
The match was becoming increasingly scrappy with both sides struggling to create much in the way of clear-cut opportunities.
The home side made another switch when Gary Teale was withdrawn for the introduction of Graham Carey with just over 20 minutes to go.
Saints pushed forward in numbers but Lee Mair was off-target with a header from a corner.
The SPL side were left ruining missed opportunities when Ayr surged into the lead with 81 minutes on the clock.
Eddie Malone’s free-kick picked out Smith unmarked inside the box and he sent a firm downward header past the grasp of goalkeeper Craig Samson to seal their place in the semi-finals, with Carey denied the leveller by the crossbar deep into injury time.