Seven out of Phelps' eight Beijing golds have set new world records.
The US squad of Aaron Peirsol, Brendan Hansen, Phelps and Jason Lezak came in with a time of 3 minutes 29.34 seconds, following a tight race that saw Lezak holding off Australian individual world record-holder Eamon Sullivan on the closing freestyle leg.
|Phelps' Beijng golds
400m individual medley
4x100m free relay
4x200m free relay
200m individual medley
4x100m medley relay
The US was lying in third place when Phelps began his penultimate butterfly leg, pushing his team to a narrow lead by the time he handed over to Lezak.
Phelps' achievement crowns a glittering week for the 23-year-old Baltimore Bullet and a week of tumbling world records in the pool.
He now has a career haul of 14 Olympic golds to his name – a massive five more than any previous Olympian.
"I wanted to do something no one else had done in sport. This goes hand-in-hand with my goal of changing the sport of swimming," Phelps said after Sunday's race.
"The greatest thing is proving nothing is impossible...So many people said it couldn't be done, but all it takes is an imagination. That is something I have learned."
Phelps' phenomenal run of medals has dominated the games so far and his final race was expected to be watched by millions around the world.
On Saturday Spitz himself praised what he said was Phelp's "epic" performance in the games.
"He can be called the best Olympian of all time"
former Olympic medal record holder
"He can be called the best Olympian of all time," Spitz told US broadcaster NBC, "not because he has more gold medals than anybody but in the way he's handled himself and in the way he's actually won under a tremendous amount of pressure."
Sean Gregory, sports reporter for Time magazine told Al Jazeera Phelps' new mark of eight Olympic golds could prove unassailable.
"As far as individual accomplishment goes, it's tough to beat what Phelps did," he said.
Phelps himself can expect to see huge financial returns after writing himself into Olympic history books.
His sponsor, swimwear maker Speedo, had already promised him a $1m bonus for matching Spitz's record by winning the 100m fly on Saturday.
But having now topped that record, that sum will likely to be dwarfed by the corporate endorsements he is expected to garner having secured his title as the greatest Olympian of the modern games.