Mellouli won the 1,500 metres freestyle gold at the 2008 Beijing Olympics and used his superior speed to burst clear of his rivals and win the gruelling 10-kilometre race in the Serpentine in London's Hyde Park.
"I can't explain it, I can't really describe it," Mellouli said after pumping his chest when he finished.
"I don't think this has ever been done before. This is probably one of the toughest things to do.
"I'm a pretty solid guy and I never react but you saw that reaction, that says it all."
Germany's Thomas Lurz won the silver medal and Richard Weinberger of Canada the bronze but no-one could keep up with the 28-year-old Mellouli after he charged into the lead on the fifth of the six loops.
Britain's Dan Fogg finished fifth after a storming final lap of the course, which saw him move up from 22nd.
Mellouli quickly opened up a three-body-length lead over the chasing pack and maintained his advantage to the end, slapping the overhead touch pads to win gold in one hour 49 minutes 55.1 seconds.
"I've been struggling, with my shoulder, my elbow, I had a virus. What happened today is a miracle if you believe in miracles," Mellouli said.
"This thing just hurts. You're in pain. Once you hit a wall you just keep pushing, when you hit a wall again you keep pushing."
Lurz was 3.4 seconds behind in second place, with Weinberger a further 1.8 seconds back, in a race contested at the recreational lake in Hyde Park that was constructed in 1730 and remains an tourist destination.
A huge crowd lined the banks to watch the race, which was introduced into the Olympic programme in Beijing four years ago.
A national hero in his homeland, Mellouli became his country's first double gold medallist.
He also won the world championship for 800 metres in 2007 but was stripped of his title and banned from competing for 18 months after testing positive for amphetamines at a meeting in the United States in late 2006.
Mellouli, a student at the University of Southern California at the time of the offence, said he had taken an Adderall pill two days before he tested positive so he could stay awake to finish a university assignment.
Mellouli entered the 1,500 in London and won a bronze medal, but was no match for China's Sun Yang, who smashed his own world record.
The top 14 finishers completed Friday's exhausting event within a minute of each other. The last finisher in the 25-man field was Benjamin Schulte, a 16-year-old from the South Pacific island of Guam.
Schulte, who trains in Australia alongside Sun, took just over two hours to reach the end in the murky waters inhabited by fish, geese, ducks and swans, finishing nearly 14 minutes behind Mellouli but getting as big a roar from the crowd as the gold medallist.