Kerrin McEvoy and Almandin narrowly got the better of Joao Moreira on Tony Martin's Heartbreak City in an epic battle for the 156th running of the world's richest handicap.
For McEvoy it was a second win in the race that stops a nation, some 16 years after his first aboard Brew in 2000, while for owner Lloyd Williams, in whose colours the six-year-old was one of four to race, it was a record fifth success, Racing Post reported.
For trainer Robert Hickmott it was a second victory in five years after saddling Green Moon to win in 2012.
And yet for so much of the home straight it looked like being a different story - and just the latest, and greatest, example of Tony Martin's genius as a trainer.
As Moreira angled Heartbreak City out off the bend and flew past Hartnell with 400m to run, it looked like a race-winning move.
He had Almandin for company, as he had for the entirety of the race with McEvoy choosing to track Moreira in midfield and the two never more than a length apart, but the superimposed white lines on the track every 100m kept passing with Heartbreak City's head narrowly in front.
By the 100m marker his half a length lead had been whittled down to little more than a head every time his nose was down. The lead switched hands with every head bob for 50m until Almandin's outside surge finally took him to victory - and ensured Martin's gallant Ebor winner lived up to his name, reported Racing Post.
There was a head between the pair by the line, as they pulled well clear of Hartnell who was four and a quarter lengths back in third. He in turn had plenty of clear water to the chasing trio of Charlie Appleby's Qewy, Who Shot Thebarman and Sheikh Hamdan's Almoonqith, who finished all but in a line, two and a quarter lengths behind.
McEvoy, who is married to the sister of last year's winning rider Michelle Payne, ended a 16-year wait between victories in the race - the longest of any multiple Melbourne Cup-winning jockey. He said: "Words can't describe it, I'm just ecstatic.
"To be able to win another one, I'm just over the moon. Lloyd had faith in me to get the job done, the horse had a dream run through.
"I was worried that Joao was kicking as well as me but my horse was just so game, he put his ears back and had a crack. He's been so well handled by Lloyd, it was a really canny job to get him qualified and just give him a nice four week break. He was so fresh and he travelled like a star the whole way, I was never off the bridle."
Almandin won the Group 3 The Bart Cummings, a win-and-you're-in qualifier for the Melbourne Cup, at the start of October.
Martin was magnanimous in defeat. He said: "I'm so happy for all the owners, my family and all the crew that work for us back home. It was a wonderful performance, he ran full of heart but it's just a shame we couldn't quite get him across the line."
Godolphin's John Ferguson added: "Oceanographer was flat after his run on Saturday, backing him up didn't work. We're absolutely thrilled with Hartnell and with Qewy too. Qewy has come a long way from when I had him, I don't think he'll talk to me now!
"It's a great result, we're delighted and we've had a great campaign here. It's confirmed what we believed we could achieve down here, we've learned a hell of a lot and we will be back."
Of the other European raiders, Saeed Bin Suroor's Beautiful Romance was seventh, Big Orange was tenth, Bondi Beach 13th, Secret Number, also trained by Bin Suroor, was 21st and Wicklow Brave 22nd.