The Victoria native was forced to leave his position near the front of the pack to repeat a turn after missing a buoy, but raced back into contention to finish just seven tenths of a second off the podium.
Spyridon Gianniotis of Greece defended his title in a gruelling and combative race, surging ahead on the final lap to avoid a sprint with Olympic champion Oussama Mellouli of Tunisia.
Gianniotis finished in one hour 49 minutes 11.8 seconds in the waters of Barcelona's harbour.
Five-time world champion Thomas Lurz of Germany finished second, 2.7 seconds behind, and Mellouli was third, 7.4 back.
Weinberger finished in 1:49:19.9 after missing a buoy midway through the race, an error he called "fatal."
"I'm one of the strongest guys out there and I know I could have come first," said Weinberger, who won bronze at the London Olympics last summer. "It's just so disappointing that I made such an amateur mistake and I didn't notice the turning buoy pass on my right."
Meanwhile, Victoria's Eric Hedlin finished 23rd in the 66-swimmer field in a time of 1:49:54.5.
"I didn't exactly get the position I wanted but it's not that I'm disappointed," said the 20-year-old world championships rookie. "From a perfect race you don't really learn very much so I guess I learned quite a bit during that one, mainly things involving pacing."
Mellouli won Saturday's 5K race with an impressive sprint finish and he was at or near the lead for much of this race but Gianniotis took the initiative on the final lap to gain a clear lead of two bodylengths ahead of his chasers.
"I wasn't feeling so good but I picked it up and got in the first places the last lap and I said to myself, 'That's it, go in front and whatever happens happens,'" Gianniotis said. "I'm quite good on sprinting but not like Oussama. ... I knew that if it goes to the end, even if he's more tired than me he's got more speed than me, so I tried to stay in front."
Having skipped the 5K, in which Lurz took bronze, Gianniotis appeared fresher than his rivals.
"I pushed a bit in the last 300 metres to make a bit of a (gap) in case he came really hard," Gianniotis added. "The last 50 metres I've never felt so bad in my life. I was nearly fainting. ... My hands were (shaking).
"My heart was pumping so hard I couldn't keep up with my blood," Gianniotis added. "I just put my head down and swam hard."
While the race began at noon under a searing sun with an air temperature of near 30 degrees C, water conditions were ideal at 25 degrees.
Swimmers completed four laps over the 2.5-kilometre L-shaped course in Barcelona's harbour, as fans watched from the shore.
Lurz lost time early on due to fighting around the buoys.
"It was very bad. And it's always the guys not finishing in the first positions," he said. "I want to swim and not fight. It just costs power. But that's open water."
Mellouli had to fend off some underwater kicks and jabs from Damien Cattin-Vidal of France, who finished fourth, in the final kilometre.
"Every time I tried to move he got super physical, so I couldn't move," Mellouli said.
Gianniotis enjoyed the combat.
"You're going to get hit, you're going to get pushed. It's rough," he said. "It's really hard and hard is what I like."
Gianniotis finished fourth at the London Games and wasn't quite sure if the world title was redemption.
"It's not the same," he said. "But I came here with only 3 1/2 months training and I won. After the Olympics I was feeling very bad psychologically but this is sport and I said to myself I wanted to come back."
The London race was held in the Serpentine in Hyde Park.
"The Olympics were a spectacular event but it was in a lake and it didn't feel like real open water," he said.
With Greece still mired in economic crisis, Gianniotis dedicated the victory to his countrymen.
"I wanted to do this at the Olympics and that's why I was upset," he said. "This is for my country, my coach and then people who love and support me. My federation has cried a lot for me and I thank them a lot."
Early in the race, Zu Lijun of China was disqualified for failing to swim around a buoy.
The women's 10K is scheduled for Tuesday.
— With files from The Canadian Press