Sun, a winner in the 200m and 400m freestyle already in Budapest, produced an uncharacteristically poor performance.
Italy's Gabriele Detti was the surprise winner of the men's 800m freestyle -- the event Sun had dominated for the last three world championships -- as the 25-year-old Chinese flopped and trailed home in fifth.
Sun, a winner in the 200m and 400m freestyle already in Budapest, produced an uncharacteristically poor performance and was never in contention as he finished 8.10 seconds off Detti's winning time of 7:40.77.
"I was too tired towards the end, my arms and legs were very tired," said Sun. "I spent 70 percent of my energy on the 200m and 400m and I didn't have enough left, when I go back home I will reflect on whether to keep doing the 800m."
Ledecky made history on Tuesday as the first woman to claim 12 world championship titles, but the 20-year-old was pipped to gold in the women's 200m freestyle by Italy's Federica Pellegrini.
Ledecky, a gold medallist in the 400m, 1500m and 4x100m freestyle in Hungary, was forced into a share of second place, but vowed that losing will motivate her for years.
Former Olympic champion Pellegrini snatched gold on the wall, winning in 1:54.73, as Ledecky and Australia's Emma McKeon both clocked 1:55.18 to take silver.
"I knew it was going to be a tough field, but I can't complain about the silver," said Ledecky. "That will light some fire under me for the next couple of years."
Victory for Pellegrini sparked a good night in the pool for Italy, with Gregorio Paltrinieri earning bronze alongside his compatriot Detti's triumph in the 800m freestyle.
Britain's Adam Peaty continued his domination of the men's breaststroke sprint events by backing up his victory in the 100m final with gold over 50 metres.
The 22-year-old only narrowly missed breaking his own world record again as he won 50m gold.
Peaty clocked 25.99 seconds in the final, just 0.04sec short of his record time in Tuesday's semi-finals.
"I know I can do faster than that, maybe in a few years I can come back and actually do it, but for now I'm more than over the moon," said Peaty.
South Africa's Chad le Clos avenged his defeat in the 200m butterfly final from the 2015 world championships, beating Hungary's Laszlo Cseh on his home patch.
Le Clos, the 2012 Olympic champion, clocked one minute 53.33 seconds with Hungary's Cseh, 0.39sec behind.
"It was an emotional race, before, during and after it," said Le Clos, who had braced himself for a raucous atmosphere at the Duna Arena.
The noise was near-deafening as the crowd roared on Cseh and Tamas Kenderesi, who finished fourth.
"I knew it was going to be difficult with everyone cheering for the two Hungarians," said Le Clos.
"I'm very humbled to have come out on top and reclaim the gold medal that I lost last year," he added, referring to his fourth-placed finish in the 2016 Olympic final.
The United States quartet ended the night by smashing the world record in the mixed 4x100m medley relay for the second time in the space of a few hours.
Matt Grevers, Lilly King, Caeleb Dressel and Simone Manuel clocked three minutes 38.56 seconds in the final after the USA had shattered the previous record with a time of 3:40.28 in the morning's heats.
This is only the second world championships featuring the mixed medley relay, which will also be included at the 2020 Olympics, and the USA took more than three seconds off Britain's record set two years ago.