(CNN) -- Britain's Ben Ainslie became the most decorated Olympic sailor in history with his fourth successive victory -- and then declared it was his last involvement at the Games.
The 35-year-old came ninth in Sunday's medal race but, crucially, finished ahead of his main rival for the gold medal -- Denmark's Jonas Hogh-Christensen.
Pieter-Jan Postma, from the Netherlands, had an opportunity to leapfrog both Ainslie and Hogh-Christensen but a poor last stretch saw him finish fourth overall. France's Jonathan Lobert took the bronze.
It marked a fairytale ending for Ainslie, who had trailed Hogh-Christensen through the majority of the competition, only to take gold at the last in front of a vociferous crowd at Weymouth, on England's south coast.
But he said he was unlikely to defend his crown for a fifth time at the 2016 Olympics in Rio.
"It's times like this you are supposed to come out with something clever but I can't think of anything," Ainslie told the host broadcaster, after eclipsing Denmark's Paul Elvstrom as the sport's best.
"I am speechless. I am just so glad for everyone who has supported me over the last four years. It has been an amazing Olympics.
"After six races I was in a bit of trouble. Thankfully I turned things around and got it right when it counted. This was one of the hardest courses I have raced on and I don't want to do anything like that again.
"You can never say never but I don't think I can sail one of these again, it's killing my body so I don't think you will see me in Rio. But it's the best way to bow out at a home Olympics."
Ainslie claimed a silver medal in the Laser class at the Atlanta Games in 1996 and then gold four years later in Sydney.
He switched to the heavyweight Finn division at Athens in 2004 and took another gold, which he successfully defended in Beijing.
Ainslie endured a disappointing start to the regatta and didn't beat Hogh-Christensen until the seventh race but maneuvered himself into contention in the last of the fleet races.
The Briton kept himself ahead of his Danish rival but slipped down the field and was dangerously close to losing his gold when Postma challenged New Zealand's Dan Slater for second place.
But Postma clipped his rival's boat and had to take a penalty turn, ending his hopes and handing Ainslie another Olympic triumph. It came as a relief to Ainslie, who had been expected to deliver in front of his home crowd.
"It's been incredibly hard -- there's a huge amount of pressure to perform at a home Games," he added. "It's been the hardest couple of weeks of my life but you just have to get on with the job.
"I learned to sail for fun so it's been a long road but I have had a lot of support over the years and I am just so glad to have done it."
Earlier in the day, Team GB's Iain Percy and Andrew Simpson were piped to the Star gold medal by Sweden's Max Salminen and Fredrik Loof.
Percy and Simpson, who won the two-hand Star class in Beijing four years ago, went into the final race leading but could only finish eighth, leaving the door open for the Swedes.
The Brazilian pair of Robert Scheidt and Bruno Prada took the bronze medal.