It is the fourth consecutive Olympics in which Ainslie has won a gold medal and his five medals overall make him the most decorated sailor in the history of the Games.
He won a gold in the Laser class in Sydney before his current streak of Finn titles and he also grabbed a Laser silver medal in Atlanta.
Ainslie got the best of Denmark's Jonas Hogh-Christensen, who had led the event from the beginning after winning the opening two races July 29.
The Finn class (heavyweight, one-person dinghy), like all fleet races in the Olympics, awards 1 point to the winner of an individual race, 2 points to the second-place finisher and on down the line.
There are 10 preliminary races and the worst performance from those 10 is thrown out. The points in Sunday's medal race counted double.
Going into the medal race, Hogh-Christensen had 26 points and Ainsley had 28. That meant that unless Hogh-Christensen won the medal race, all Ainsley had to do was finish in front of Hogh-Christensen to win gold.
Hogh-Christensen never threatened to win the final race Sunday, getting stuck back in the pack of the 24-boat field. Ainsley inched in front of him and made sure he stayed there. Ainsley finished ninth in the race and Hogh-Christensen 10th.
Both wound up with 46 points, but because Ainsley was ahead of his rival in the medal race he won the gold medal -- much to the delight of the thousands who flocked to the hilllsides alongside Weymouth-Portland Harbor to watch the races.
Hogh-Christensen settled for the silver and France's Jonathan Lobert of France won the bronze, moving up from fourth place by winning the medal race.
The other Olympic final Sunday showed the volatility of fleet races.
The Swedish boat in the Star (keelboat) class began the medal race in third place, 12 points behind the British leaders.
Sweden's Fredrik Loof and Max Salminen, however, won the medal race and grabbed gold when the British pair of Iain Percy and Andrew Simpson could manage only an eighth-place finish.
Percy and Simpson salvaged a silver medal while Brazil's Robert Scheidt and Bruno Prada won the bronze.
The women's windsurfing class completed its 10 preliminary races with Spain's Marina Alabau Neira holding a 14-point lead going into the race.
Dorian van Rijsselberge of the Netherlands will take a massive 22-point lead into the medal race in men's windsurfing.
Celebrity Breakups and divorces of 2014 [PHOTOS]