An explosive second half from rampant Ayr sent them through to Round Three for a tie with Premier League side Inverness.
After a dry first half in which it was tackles and not chances being the name of the game, things quickly came to life after the re-start.
Gareth Wardlaw put United ahead when he bundled home an Ian Cashmore cross after beating substitute keeper Stefan Gonet to the ball.
Soon it was 2-0 when skipper Raymond Logan crossed for Chris Robertson to power home a header.
It was all Ayr and they made it threewhen Wardlaw played in Robertson and he lashed home from 12 yards.
But Morton quickly sent nerves jangling when Peter Weatherson netted with 22 minutes still to go and it was panic stations when Chris Templeman rammed home a second with 10 minutes left.
The closing stages saw a flurry of red cards with Ayr's Paul Weaver and Morton's Derek Lilley and Jason Walker all going off in separate incidents as United held on.