The Manxman beat Germany's Marcel Kittel to the line during stage six to take him one above France's five-time Tour winner Bernard Hinault.
He is now five behind another five-time Tour winner, Eddy Merckx of Belgium.
Fellow Briton Dan McLay was third in a bunch sprint with Team Sky's Chris Froome safely home in the peloton.
On a relatively flat stage from Arpajon-sur-Cere to Montauban, set up for sprinters, there was no great movement in the general classification as Belgium's Greg van Avermaet remained in the yellow jersey.
The BMC rider still leads France's Julian Alaphilippe (Etixx-Quick-Step) by five minutes and 11 seconds, with 2013 and 2015 champion Froome a further six seconds behind.
Relive the final stages of Cavendish's thrilling win
Having already won the opening stage of this year's Tour to take hold of the yellow jersey for the first time, and won a photo finish on stage four, a third Cavendish victory came after the Team Dimension Data rider emerged from the back of the pack.
It also ensured he took hold of the leading sprinter's green jersey, overtaking Slovakia's Peter Sagan (Tinkoff).
"Oh my god, that was terrifying," he told ITV4. "That was like the old days, just wheel surfing. There are almost two finish lines, and I was a little bit too far back so it was carnage in the final straight, there were guys coming from everywhere.
"I was fighting to be on Marcel Kittel's wheel, I wasn't sure if they were that organised, but I knew it would be the right thing to go early because it was downhill. I went for the line and I had to come again, I did what Marcel has done to me in the last four years and held on."
Fortuneo-Vital Concept's McLay, who earned a fourth top-10 finish of his maiden Tour, was actually finishing faster than Cavendish or Kittel but the 24-year-old ran out of tarmac.
Despite Van Avermaet eking out a five-minute lead on Wednesday, there was no desperation from the main general classification contenders given he is not considered a main rival, and they will get a better chance to claw it back when the Tour heads to the Pyrenees on Friday.
The main task for the likes of Froome, and Movistar's Nairo Quintana and Alejandro Valverde, was to stay out of trouble as the sprinters jockeyed for a last chance of glory before the ascents take their toll.
Once the breakaway pair of Jan Barta (Bora-Argon) and Yukiya Arashiro (Lampre-Merida) were caught by the peloton with 21km to go, Froome's team-mates kept him at the front of the main pack to ensure he was not involved in any crashes.
Fellow yellow jersey rival Alberto Contador remains six minutes and 39 seconds off the leader's pace, while Vincenzo Nibali looks unlikely to mount a challenge after winning the 2016 Giro D'Italia.
1.  Mark Cavendish (Britain / Dimension Data)    4:43:48"
2.  Marcel Kittel (Germany/Etixx - Quick-Step) same time
3.  Daniel McLay (Britain / Fortuneo)
4.  Alexander Kristoff (Norway / Katusha)
5.  Christophe Laporte (France / Cofidis)
6.  Peter Sagan (Slovakia / Tinkoff)
7.  Dylan Groenewegen (Netherlands / LottoNL)
8.  Edward Theuns (Belgium / Trek)
9.  Bryan Coquard (France / Direct Energie)
10. Shane Archbold (New Zealand / BORA)
1. Greg van Avermaet (Bel/BMC Racing) 30hrs 18mins 39secs
2.  Julian Alaphilippe (Fra/Etixx-Quick-Step) +5mins 11secs
3.  Alejandro Valverde (Spa/Movistar) +5mins 13secs
4.  Joaquim Rodriguez (Spa/Katusha) +5mins 15secs
5.  Chris Froome (GB/Team Sky) +5mins 17secs
6.  Warren Barguil (Fra/Giant) same time
7.  Nairo Quintana (Col/Movistar)
8.  Pierre Rolland (Fra/Cannondale)
9.  Fabio Aru (Ita/Astana)
10. Daniel Martin (Ire/Etixx-Quick-Step)
Mark Cavendish edged a thrilling sprint to win a 29th Tour de France stage, moving him outright second in the race's all-time standings.