After the gruelling 10km open-water swim, the 24-year-old Weertman touched the electronic pads at the finish line just before veteran swimmer Spiros Gianniotis of Greece, giving the Dutchman his first gold medal in his first Olympics.
The official results showed the first two swimmers with the same time of 1:52:59.8. Marc-Antoine Olivier of France, 20, finished 2.2 seconds behind to win the bronze medal.
For Weertman, current European champion in the distance, it was not luck. He had been training hard on the touch pads for the last few weeks, but he did not expect to be struggling with a pack of six other racers at the finish line.
In the last of eight lengths on the waters off the famous curving beach, Weertman pulled ahead of the leader for most of the race, Jarrod Poort of Australia, and was soon joined by several other heavyweights.
"Gianniotis got in front and I knew he was going to win a medal so I thought I have to get next to him, it's the last 200 metres," said Weertman.
On the touch pads, he said, "we have been practising a lot just to get the finishing touches, pun intended, and I had a perfect finish. That's what made the difference here today."
He emerged from the water mentally and physically drained and was in a golf cart when his friend called him.
The Dutch prime minister, Mark Rutte, called him too before the medal ceremony, and he could hear the cabinet clapping in the background.
Weertman's victory means a sweep by the Dutch in marathon swimming after Sharon van Rouwendaal, 22, won the women's 10km open water race on Monday.
Marathon swimming, a sport rooted in swimmers who braved the English Channel, is relatively new to the Olympics. Tuesday's race was the first of three editions to take place in the ocean, where the water temperature was a comfortable 21 C.