The Australian had opened up a war of words against his Chinese opponent in the buildup to the Olympic 400 meters freestyle final, saying: "I don't have time or respect for drug cheats."
Sun served a doping ban in secret in 2014, news of which was only announced in China retrospectively, and Horton ignored his rival when he attempted to make contact during a practice swim.
"It got played up a bit, but he splashed me to say 'Hi' and I ignored him," Horton added. "He wasn't happy about that so he kept splashing me, and I just go in and did my thing."
Sun has not just courted controversy with his drugs ban -- in 2013, he was also detained by police for seven days after being involved in an accident while driving without a license. At last year's world championships, he was accused of assaulting a female Brazilian swimmer after an argument in the warmup pool.
In Saturday's evening session race, both Horton and Sun were off the early pace of Britain's James Guy, a 200m specialist who led the race between 100m and nearly 350m before fading badly.
It paved the wave for the leading pair to come down the final lap stroke for stroke, Horton touching in 3 minutes 41.55 seconds -- just 0.13 seconds clear of his rival.
The pair appeared to continue their ill feeling by ignoring each other while Horton was congratulated by the rest of the field. Italian Gabriele Detti took the bronze.
Asked about their frosty rivalry after winning gold, Horton, who later shook hands with Sun at the medal ceremony, told reporters: "I don't know if it's a rivalry between me and him -- just me and athletes who have tested positive I guess."
Of his own race, he added: "In another big final, it's about touching the wall first and that's what I did. I had my eye on everyone else in the field." Of the gold, he said: "It hasn't really sunk in yet but it's very exciting.
Sun, meanwhile, broke down in tears surrounded by Chinese media after his defeat.
New medley champion
The men's 400m individual medley was dominated by the United States at recent Olympics. It had previously been the mainstay of world record-holder Michael Phelps and Ryan Lochte. This time, 2004 and 2008 champ Phelps had opted not to compete in the U.S. trials while 2012 winner Lochte failed to qualify.
That gave Chase Kalisz the chance to lead the American charge, but he looked well out of contention only to claw himself within a whisker of the lead after the third leg, the breaststroke.
However, Japan's Kosuke Hagino, who had warned he was "in the best shape of his career" and was fueled on by Olympic pressure, delivered to pulled clear. His time of 4:06.55 was the third fastest of all time behind Phelps and Lochte.
It made amends for him having to miss last year's world championships after fracturing his elbow when falling off his bike in training.
Kalisz, who fittingly perhaps trains with Phelps and is also under the guidance of coach Bob Bowman, had to make do with silver. Hagino's compatriot Daiya Seto picked up the bronze.
It was a day of world records in the pool, with both Hungary's Katinka Hosszu and Adam Peaty of Britain lowering best times.
Hosszu shattered the women's 400m medley milestone mark of 4:28.3 -- set by China's Ye Shiwen -- knocking more than two seconds off the time to win gold by almost five seconds over America Maya Dirado, with Spain's Mireia Belmonte Garcia completing the podium.
Nicknamed "The Iron Lady," Hosszu had considered quitting after a disappointing London 2012, admitting to suffering depression. But the 27-year-old has dominated the medley events ever since and looks like to strike further gold in Rio, with four more individual events.
Hosszu's gold took Hungary's tally in Olympic history to 169, the most ever won by a nation never to have hosted the Games.
Peaty broke his own world record in the 100m backstroke heats (57.55) and could have lowered that time still further in the semifinal but eased off at the end. He looks a banker for gold now having beaten the rest of the field by 1.5 seconds.
The night's final race -- the women's 4x100m freestyle -- was a one-sided battle between Australia and the United States.
Not even having one of the dominant forces of women's swimming on the final leg, Katie Ledecky, could claw back the deficit as the Australian quartet of sisters Cate and Bronte Campbell, Emma McKeon and Brittany Elmslie broke the world record to win gold.