The 35-year-old replaced Denmark's legendary Paul Elvstrom as the Games' most decorated sailor after triumphing on home waters in the Finn class, in front of thousands of supporters in Weymouth.
Ainslie faced fierce resistance throughout the week from Elvstrom's countryman Jonas Hogh-Christensen, although he managed to finish ahead of the Dane in this afternoon's medal race to increase his Olympic haul to four golds and a silver.
Hogh-Christensen came into the medal race with a two-point advantage over Ainslie, ahead of whom he finished in seven of the 10 opening series contests.
The British sailor knew he needed to finish ahead of the Dane if he was to win gold, but could not afford to sail him down the fleet as that would have given the Netherlands' Pieter-Jan Postma a chance of winning gold.
The Host Nation favourite did not get off to the best of starts and he failed to control Hogh-Christensen as the fleet separated heading up towards the first mark.
However, Ainslie rounded the top-mark in fifth - gold medal-winning position - with the Dane 17 seconds behind in ninth.
He had a great first downwind leg rounding the second mark just behind race leader Jonathan Lobert of France.
I am pretty speechless. It has been a tough week.Ben Ainslie
Ainslie was in control heading to the third mark and remained ahead of Hogh-Christensen, who attempted a breakaway on the last upwind leg.
The tactic did not work as Ainslie stayed ahead around the fifth mark, but the Briton was ninth and Postma had moved into second - positions that would have seen the Dutch sailor win gold.
However, attention from New Zealand's Dan Slater put Postma off towards the sixth mark and he eventually finished fifth, while Ainslie came in ninth ahead of Hogh-Christensen to win gold in a medal race won by Lobert, who took bronze ahead of Postma.
Afterwards Ainslie said: 'I am pretty speechless. It has been a tough week. There was amazing competition, especially from Jonas Hogh-Christensen from Denmark, but this was the time to do it in front of a home crowd.
'I am just so glad for all the people that supported me over the years, all the people that came here to wave me on and all the people that have written in and supported us across the country.'
Asked about his future and competing at the 2016 Olympics in Rio de Janeiro, he added: 'You can never say never. I am not going to do a Steve Redgrave here, but I don't think I could sail again.'