On what was a superb night for the USA, Missy Franklin won the 200m Backstroke in a new world record.
Phelps clinched his 17th Olympic gold medal, and 21st medal overall, when he came from seventh at the halfway point to win in 51.21 ahead of Chad le Clos, his conqueror in the 200m, and Evgeny Korotyshkin, who shared second place.
It was the final individual race of the 27-year-old's career, with just the 4 x 100m Medley Relay to come before the Baltimore swimmer bows out of competition.
He said: 'I am just happy that the last one was a win, that is all I wanted coming into tonight.'
Meanwhile, Ledecky led from start to finish and was under world record pace until the final few metres as she touched in 8:14.63, the second fastest time in history behind Rebecca Adlington's world record from Beijing 2008.
Mireia Belmonte Garcia was 4.14secs adrift in second, with Adlington securing her second bronze of the week in third.
Franklin claimed her second individual title of the week when she lowered Kirsty Coventry's world mark to 2:04.06, while Florent Manaudou of France won the men's 50m Freestyle in 21.34.