The win gives the global racing operation Godolphin its first Cup win, while jockey Kerrin McEvoy won for the third time.
The race was marred when the Aidan-O'Brien-trained The Cliffsofmoher broke down at the winning post the first time around, breaking its leg. The horse was euthanased after the race.
The forecast rain had arrived early on the day of the Cup, with more than 50mm falling in the hours leading up to the race.
The track was downgraded from good to a Heavy 8, before the rain passed, allowing the course to come back to a Soft 6 at race time.
Another Aidan O'Brien horse, Yucatan, had gone off as favourite, ahead of English stayer Magic Circle.
But both horses finished back in the field, as Cross Counter and Marmelo produced stunning closing speed to pass the leaders in the straight and fight the race out between them.
Trainer Charlie Appleby was delighted after the race.
"It is a very special day for us all. But more importantly, it is a special day for his highness, Sheik Mohammed [bin Rashid Al Maktoum] and team Godolphin," he said.
"Obviously three of us coming into the race today, we were all [agreed] that we would try to get this result. But whoever had won it, we would have all been congratulating one another.
"For me, it is a very special to be here, but like I say, for a team it is just fantastic for everybody.
"I have spoken to his highness and he's over the moon about this result."
Godolphin's other horses were the James Cummings-trained Avilius, who finished 23rd, and Caulfield Cup winner Best Solution, who came eighth.
Jockey McEvoy had won on Brew in 2000 and on Almandin in 2016. He now joins Damien Oliver on three wins, behind only Bobby Lewis and Harry White with four victories.
