St Johnstone are into the Scottish Cup quarter-finals.
A Callum Hendry double cancelled out an early Ayr opener and the Perth men did a professional job thereafter to not let their 10-man opposition back into the game and send over 1,000 of their fans back up the road with hopes of Hampden glory still alive.
It was the worst possible start for Saints, however.
They were sloppy in the first few minutes and were punished when Ayr scored a fourth minute goal through Aaron Drinan.
It took a while for things to improve but the Perth side were level on 18 minutes after they had started to get a bit of control.
David Wotherspoon crossed from the left and, with keeper Ross Doohan caught in two minds whether to come and challenge for it or stay on his line, Hendry headed home from close range, though there was a possibility that it could have been an Aaron Muirhead own goal.
There was no doubt about who made a crude challenge on Liam Craig in midfield midway through the half and got a straight red card for it – Muirhead.
Going down to 10 men was bad enough for Ayr but within seconds of the play re-starting they were a goal behind as well.
Drey Wright crossed to the back post and Hendry gave Doohan no chance with his header.
As you would expect when a Premiership side has a one-man advantage and a lead over a Championship outfit, Saints had a lot of possession in the second half.
There were a lot of near things, with a Wotherspoon shot that was tipped round the post and a Stevie May chip that grazed it the pick of them.
Saints’ failure to put the game beyond doubt mattered not. They saw out the contest with little fuss and their place in the last eight draw was secured.