On a sweltering morning, the 21-year-old came home in 56:34.2 seconds with Okimoto, who led for much of the second lap, a mere 0.2 seconds back and her compatriot Ana Cunha some 10 seconds behind in third.
Anderson's success, her first medal at a world championships, adds to the silver medal she won last year as a member of the U.S. Olympic 10-km open water team.
"I have experience doing 10km but the 5km is half the distance and double the fun," she told reporters.
"My plan for the second half of the race was to get beside Poliana and draft off of her," she added.
"I waited for the perfect moment to spring ahead. You don't really know how much you have left, but it was a good finish."
In the men's race Tunisia's Oussama Mellouli became the first swimmer to win Olympic and world titles in both the pool and open water when he snatched a narrow victory in the 5km event in Barcelona.
The 29-year-old North African powered around the two laps of the world championship harbour course at the end of the Rambla tourist drag in the heart of the Catalan capital in 53 minutes 30.4 seconds.
Canada's Eric Hedlin was just over a second behind with a time of 53:31.6 to take silver and Thomas Lurz of Germany was third with 53.32.2.
Mellouli won the 800 metres freestyle world title in Melbourne in 2007 but was stripped of his medal and banned for 18 months after testing positive for amphetamines.
He returned to take 1,500 metres freestyle gold at the 2008 Beijing Olympics and won the same event at the 2009 world championships in Rome.
In open water at last year's London Olympics, he won the marathon, beating Lurz into second with a late burst.
- Sports & Recreation
- Oussama Mellouli