For a long time, it looked like Ayr would leapfrog their visitors after Jamie Adams gave them a deserved 14th-minute lead.
It was a route one effort and a dreadful way for Saints to concede, Brian Gilmour swinging in a free-kick from wide left and Adams climbing highest at the back post to nod home.
Gilmour was at the heart of the home team’s industry and he tested Scott Gallacher with a low cutback which the keeper retrieved at full stretch.
The Paisley side were struggling to create but they sprung into life after 24 minutes with a John Sutton cross which the inrushing David Clarkson fired wide.
Kevin Nisbetheld off two challenges before firing over. Ayr could have doubled their advantage when the influential Gilmour cut the ball into the path of Gary Harkins but the former Dundee skipper couldn’t to finish.
Saints began the second half with more purpose and Ryan Hardie was twice foiled by Greg Fleming.
Clarkson headed narrowly wide from a cross by sub Tom Walsh as Saints at last began to ask serious questions of the home defence.
But the Paisley’s side finishing was wayward and Ayr could have punished. Harkins had a shot deflected over and Daryll Meggatt saw a header saved.
However, Saints were spared when Walsh headed home after a long throw from Lawrence Shankland eluded the home defence.