Townend and his horse Cooley Rosalent were third going into Sunday’s showjumping phase.
But a clear round saw them overtake Tom McEwen on JL Dublin and world champion Yasmin Ingham on Banzai Du Loir to take the title.
The trio are all hoping to be selected for GB for the Paris Olympics this summer.
“I can’t tell you how proud I am of this horse,” said Townend after his victory.
“I’m still in shock. This is just the most special event in the world and a special day in all of our lives.”
Townend, who was making his 100th start at five-star level, was in joint eighth after Friday’s dressage but moved into medal contention after Saturday’s cross-country.
McEwen, who won team gold alongside Townend in Tokyo and also took individual silver, led going into the final day on 28.6 – with Ingham on 31.6 and Townend on 31.8.
However, both McEwen and Ingham had a fence down while McEwen also incurred a time penalty, leaving him on 33.8 and Ingham on 35.6.
The win for Townend, which comes after his success at Burghley last year, sets the 41-year-old from Yorkshire up for a potential Rolex Grand Slam victory at Badminton next week.