Favourite Leading Light denied the Queen a second straight triumph in the Ascot Gold Cup by beating her horse Estimate in a thrilling finish.
It was a brilliant end to the contest as the pair and Irish raider Missunited fought it out to the line.
But it was the 10-11 shot, ridden by Joseph O'Brien for his trainer father Aidan, who grabbed the lead late on.
Estimate (8-1) was second with Missunited (40-1) in third in the two mile and four furlong race.
"When you win it is always a good ride, there's no such thing as a bad winning ride," said Joseph.
It was a sixth Gold Cup win for Aidan O'Brien but a first for his 21-year-old son.
After winning the Queen's Vase and St Leger last year, the four-year-old showed he was in good form again with a win at Navan last month.
O'Brien waited patiently as Missunited set the pace from the start. Estimate and Ryan Moore were also in the middle of the field and although the Queen's horse looked good on the home turn, she was kept in by Leading Light and when a gap opened up, the favourite was too strong.
O'Brien added: "I kept a straight line, Ryan Moore was looking for a bit of room but I was entitled to keep a straight line.
"He had a little look when he got to the front and then went a bit to his left. He's a big, lazy horse but I think he's better at a mile and six.
"I was rowing away on him but I had loads left, I was trying to hold off asking for everything for as long as I could. Ryan gave me a bit of help by coming up my inside as he pushed me along a bit - this fellow is as tough as nails."
Aidan O'Brien was celebrating his second win of the day after Joseph guided Bracelet to win the Ribblesdale Stakes earlier on the card.
"He's idle, but he was in a lovely position and settled well," he said of Leading Light. "He was very lazy when he got there. Joseph was trying to keep him with company.
"I'm so lucky to have the horses and work with the people that I do, I'm in a very lucky position and the lads have unbelievable horses with unbelievable pedigrees and it (Ballydoyle) is an unbelievable place to train from."
John Warren, the Queen's racing advisor, said of Estimate: "It was tremendous, she was so brave and the Queen got such pleasure from it.
"Ryan said it was a career-best. Having no prep, everything was against her so to run so well was tremendous."
But there was a sting in the tail for the winning jockey after he received a seven-day ban and a £3,000 fine for excessive whip use in the race and he was also given a further two-day ban for a similar offence in a later race
Also on Thursday, Frankie Dettori notched up his 49th Royal Ascot winner when the 8-1 chance Baitha Alga triumphed in the Norfolk Stakes, beating another O'Brien-trained runner, The Great War, who finished down the field.