The Richard Hannon-trained Presto Shinko took the totesport Ayr Gold Cup by a desperately short margin.
Stewards' Cup runner-up Fonthill Road seemed to have the race in the bag with a furlong to go, but 12-1 shot Presto Shinko came again late to take the win.
Irish raider Majestic Times was the same distance back in third as he led home the stands-side group.
Winning jockey Seb Sanders said: "I was possibly in front too soon, but I thought what the hell, I'll go for it."