Quito, ridden by Tony Culhane, stuck his head out on the line to take the Tote Ayr Gold Cup. The 20-1 chance just finished ahead of Seel of Approval with the well-fancied Fire Up the Band back in third and Fantasy Believer fourth.
It was a double for Culhane, who had earlier won the Ayrshire Handicap on Polar Bear.
Culhane guided his horse over to the far side at the break and timed his run to the line superbly to win by a head.
The horses on the far side had a definite advantage in the six-furlong sprint with the first four finishers all coming from that side.
First home on the nearside was Royal Millennium in fifth with the heavily-backed 7-2 favourite Frizzante just behind him on the stands' side in sixth.
Quito's victory was a sweet one for his 70-year-old trainer David Chapman, who has held a trainer's licence since 1967.
Although he enjoyed a great deal of success with the flying filly Soba in the early '80s, he admitted that this win gave him the most pleasure.
"The Gold Cup is the one everyone wants to win and it's one of the hardest - and we have had a few tries before, I think Chaplins Club finished second twice and fourth once," said Chapman.
"I bought Quito for Michael Hill, who is a steward at Wolverhampton and Newmarket, and his son Gus, from Dubai. He had won a mile race there but we have always thought he would be the right type for this race."
"The plan is to run him in the Tote Festival Handicap at Ascot next Saturday and he is also in the Cambridgeshire. I think he will get a mile and a furlong but we will have to see," he added.
David Nicholls was six-handed, including Fire Up The Band, in his bid to win the race for an unprecedented fourth year in a row.
Nicholls, who was Soba's regular jockey, said: "I am delighted for David and I know how he must feel!
"Fire Up The Band ran a great race, the ground just dried up a bit too much for him."
Tote Ayr Gold Cup
Six furlongs
1 Quito (A Culhane) 20-1
2 Seel of Approval (R Hughes) 11-1
3 Fire Up The Band (A Nicholls) 7-1
4 Fantasy Believer (K Darley) 20-1
26 ran. Dist: Hd, �l