Both sides probed early without troubling the keepers. Chris Strain threatened the Morton goal with a run but his final shot flew over.
Chris Millar supplied James McAlistair but again the shot was wide.
McAllistar went closer with a drive which Mark McGeown saved easily but Ayr should have grabbed the lead in the 14th minute when Chris Robertson rose to a Craig Conway free-kick but his header sailed over.
Morton pressed but Peter Weatherson fired yards wide and McAllister just failed to connect with Andy McLaren's cross.
Just when a half-time stalemate was looking likely, Ayr were caught out by a quick free-kick by Millar on halfway. Derek Lilley charged towards goal as desperate United players dashed back but Lilley planted a right-footed shot past McGeown via a post.
McGeown made a splendid save from Scott McLaughlin as The Ton ended the first half on top.
Millar and Jason Walker went close after the break but Paul Weaver kept David McGurn busy with a snap-shot in a rare attack.
McAllister should have made it two but blasted the ball against McGeown.
Jerome Vareille nearly levelled with a smart backheel but McGeown reacted sharply to palm the ball over.
McAllister drove in a David McGregor cross from 18 yards to double the home side's lead but Ayr were far from finished.
Chris Robertson played the ball in for sub Gareth Wardlaw who cleverly controlled the ball on his chest before firing beyond McGeown.
Ton held on to reduce league leaders Gretna's advantage to eight points.