But he now looks set to walk away from the sport while he's at the top.
"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 (for the 2016 Games)," he told the BBC.
"But it's the best way to bow out at a home Olympics."
Sailing in perfect, sunny conditions on home waters off the south coast of England, Ainslie added to his three golds and a silver in successive Games by beating Danish sailor Jonas Hogh-Christensen on points.
Unfancied at the start of the Olympics, the Dane struggled to find the winning form he has shown all week and failed in his mission to stop Ainslie surpassing the record of four golds held since 1960 by another Dane, Paul Elvstrom.
Arms aloft, with a flare billowing red smoke in each hand, Ainslie celebrated a narrow victory in front of a huge cheering home crowd packed onto the grassy slopes of the Nothe fort immediately above the race course.
"It's been the hardest couple weeks of my life," the 35-year-old said of sailing the physically demanding Finn dinghy which has caused him back and knee troubles.
His boat, known as "Rita", was the same one he sailed to victory in the two previous Olympics.
Pieter-Jan Postma of the Netherlands was beaten to the bronze overall by Sunday's medal race winner Jonathan Lobert of France.
The Briton and the Dane were ninth and 10th respectively in the race, giving them enough points to claim their medals, with Postma finishing fourth overall in the heavyweight Finn class.