The away side started the game well, but it was Ayr who had the first chance on five minutes when Michael Donald smashed the ball against the post.
Rangers composed themselves and had a chance of their own on 13 minutes, but Nicky Law could only put his half-volley over the bar.
Some tidy build-up play from Rangers created an opening for Lee McCulloch, who fired towards the goal from 25 yards out. However, the goalkeeper was equal to the strike.
Jon Daly had a huge chance from a corner just before half time, but the forward could not adjust his body in time to find the finish.
Bilel Mohsni gave Rangers the lead on 55 minutes, smashing home a half-volley from the edge of the area.
Three minutes later, Lewis MacLeod doubled the away side's lead with a fine overhead kick.
Daly had a good effort on 61 minutes, but his left-footed strike was saved well.
Some great work by David Templeton down the wing almost resulted in a chance for Daly, but the defence just about cleared to deny the opportunity.