The imposing Australian import So You Think, now trained in Ireland by Aidan O'Brien, burst into the lead and charged clear but had his bubble burst by Rewilding.
Dettori timed his run brilliantly and triumphed by a neck from the 4-11 favourite.
So You Think went into the race with positive vibes from O'Brien about the "very special" horse he has trained since he was sent to his Ballydoyle yard after finishing third in the Melbourne Cup in November.
Stablemate Jan Vermeer set the pace, and with echoes of Frankel's winning display on Tuesday, the favourite set off in early pursuit.
“I think it was trainer error, I didn't have him fit enough for this kind of race and he's given a good blow afterwards.”
Aidan O'BrienSo You Think trainer
Three-time champion jockey Ryan Moore looked to have settled matters as five-year-old So You Think cruised to the front with a powerful injection of pace.
Dettori had other ideas and got to work on Rewilding, who was third in the 2010 Epsom Derby to Workforce.
And he edged past in the Dubai royal blue colours of Godolphin, with runner-up So You Think six lengths ahead of Sri Putra in third.
The four-year-old winner had been sixth in last season's St Leger over a mile and three quarters, but he relished this trip over half a mile shorter.
It was another memorable triumph for Dettori, the Italian-born rider who claimed a famous Magnificent Seven victories at this course in 1996.
He celebrated with a trademark flying dismount after scoring his 44th Royal Ascot victory to cement his place as the current rider with the most career wins at the meeting.
"He never gave up," said Dettori. "It was a tremendous battle between two great horses.
"When I got past [So You Think] it was sheer joy - it was a privilege to be in such a great race.
"I'm delighted for Rewilding. He doesn't get the recognition he deserves, he's a very good horse and he showed his true colours today."
So You Think trainer Aidan O'Brien, meanwhile, took the blame for his horse's performance, saying: "I will take responsibility for this personally.
"Frankie gave his horse a beautiful ride, on a horse that stays a mile and a half well, he just came and got him in the last 50 yards.
Dettori jumps for joy at Prince of Wales's Stakes win
"I think it was trainer error, I didn't have him fit enough for this kind of race and he's given a good blow afterwards.
"I would think there's improvement to come."
bounced right back to his best to win the Jersey Stakes, the opening event on the second day
Winner of the Coventry Stakes last year, the Richard Hannon-trained colt had failed to build on the win and underwent a breathing operation after disappointing behind Frankel in the Greenham Stakes - leading to starting odds of 11-1.
He was carrying a penalty for his win at the Royal meeting 12 months ago, but easily caught the front-running Utley still on the bridle and quickened clear.
The well-backed favourite Codemaster came through the pack to give chase but Richard Hughes was always holding him and prevailed by half a length. Jeremy Noseda's Western Aristocrat flew home for third.
There was also a surprise result in the Windsor Forest Stakes, with another 11-1 shot
Lolly for Dolly
, ridden by Wayne Lordan, leading Chachamaidee and First City past the winning post.
Favourite Sajjhaa, ridden by Frankie Dettori, came home in fourth.
In the later races, Eddie Ahern rode 12-1 shot
to victory in the Royal Hunt Cup ahead of Dance and Dance, Invisible Man and Pendragon.
In the Queen Mary Stakes, Richard Hughes led
to victory by a short head ahead of 6-5 favourite Shumoos in a photo finish, with Caledonian Lady third and Fire Lily fourth.
And in the Sandringham Handicap,
Rhythm of Light
finished ahead of Kieren Fallon's joint favourite Dubai Queen, Winter's Night and Cape Dollar.
The Queen's horse Humdrum, however, could only manage fifth.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.