The Brit came into the stage with a 23-second lead over Romain Bardet (Ag2r La Mondiale) and a 29-second lead over Rigoberto Uran (Cannondale-Drapac), but will win the Tour by almost a minute as he came third on the penultimate stage won by Maciej Bodnar (Bora-Hansgrohe).
On paper the best time triallist of the three Tour de France GC contenders, Froome showed why he was the favourite with a fast start to his final test, setting the second best time at the first time check, just two seconds behind team-mate Michal Kwiatkowski who would eventually as runner-up on the stage.
Uran and Bardet both lost time on the flat first half of the course, but while the Colombian held his shape for the rest of the stage to finish seventh on the day, Bardet fell to pieces.
By the second time check at the top of the only hill on the course, Bardet had lost 1-17 to the leaders, fighting with his bike on the steep gradients while Froome looked as smooth as ever, pedalling with a high cadence in his aero bars.
The Team Sky rider had set off two minutes behind Bardet, but by the final kilometre he had the Frenchman in his sights, giving him something to chase as Bardet fought to hold on to his podium spot.
Bardet fought all the way to the line, only managing to hold onto third place overall by one second from Mikel Landa.
Just a few seconds later and it was the turn of the yellow jersey to cross the line. Froome, fighting to the very end, putting in a time that wasn't good enough to win the stage, but was more than enough to secure his fourth Tour de France victory with only Sunday's procession around Paris to come.
How it happened
The penultimate stage of the 2017 Tour de France got underway in sweltering heat in Marseille, the riders rolling down a start ramp in the centre of the Stade Velodrome football stadium.
Luke Rowe (Team Sky) was the first man to start, putting in a performance good enough to secure his position as the lanterne rouge, but the best early starter was Taylor Phinney (Cannondale-Drapac) with a time of 29-21.
Phinney's time stood firm for more than an hour before Maciej Bodnar (Bora-Hansgrohe) crossed the line more than a minute quicker in a time of 28-15, which was also good enough to hold off Jack Bauer (Quick-Step Floors) and Jasha Sütterlin (Movistar) both of whom came within three-quarters of a minute of the Pole's time.
The next man who could challenge Bodnar was world champion Tony Martin (Katusha-Alpecin), but the German was not able to beat Bodnar's time, falling short by just 14 seconds.
Stefan Küng (BMC Racing), another of the pre-race favourites, also finished slower than Bodnar, while Spanish and European time trial champion Jonathan Castroviejo's challenge was ended after just 50 metres when he crashed on the way out of the stadium.
The next threat seemed to come from one of Bodnar's fellow Poles: Team Sky's star domestique Michal Kwiatkowski looking to grab a slice of personal glory after three works of tireless self-sacrifice.
Kwiatkowski was six seconds fastest at the first time check, and one second faster at the top of the climb after 15.6km. With a technical descent followed by a five-kilometre flat run to the finish, Kwiatkowski was going to come close, but eventually crossed the line in second place, just one solitary second behind Bodnar.
Primoz Roglic (LottoNL-Jumbo) looked like the last non-GC contender who could challenge Bodnar's time, but the stage 17 winner looked off form as he went through the first 10km 25 seconds slower than Kwiatkowski, then suffered a mechanical on the approach to the climb to put him well-and-truly out of contention.
Warren Barguil (Team Sunweb) was the first of the top 10 off the start ramp, receiving a rapturous reception from the home crowd having being given the award for the most combative rider in this year's race. However the real interest was on those looking for victory further up the standings.
When Rigoberto Uran rolled down the start ramp at 17:00 local time, Bardet two minutes later, and Froome another two minutes further on, the fight for the yellow jersey was on.
Froome set off to boos and jeers from a hostile Stade Velodrome crowd, but looked smooth as he swept through the opening corners before settling into his rhythm on the wide roads along the coast.
Going into the stage, many had tipped Uran to be Froome's biggest threat for yellow, but at the first time check after 10km the Colombian could only go 14th fastest, 26 seconds slower than Kwiatkowski.
However Bardet went even slower, 19 seconds behind his Cannondale-Drapac rival, meaning that as things stood he had already lost second place to Uran.
The last rider through was Froome, the yellow jersey on an absolute flyer as he went through the time check just two seconds down on his Polish team-mate.
From there things were looking good for the Brit, but Uran was attacking the climb, clawing back a few seconds on the steep ascent and digging deep before the descent and flat run to the finish.
Not looking quite as strong was Bardet, who was labouring up the climb, riding out of the saddle while Froome remained locked in the aero bars.
The Frenchman was cooked, exploding on the climb to cross the time check well over a minute behind the fastest time of Kwiatkowski, potentially putting his place on the podium under threat, while Froome, continuing to look superb, was still only two seconds down.
The next moment of drama came when Rigoberto Uran took the left hand turn into the stadium, coming into contact with the barriers, but managing to stay upright. His foot briefly came unclipped, and he was quickly back underway to cross the line in an impressive eighth place on the day, and second overall.
The only two riders left on course were Froome and Bardet, the former having the latter in his sight for the final few kilometres. Bardet was fighting to keep his podium place, and just did enough to hold on by one second ahead of Mikel Landa.
While Bardet had to suffer all the way to the line, Froome had less to worry about in terms of his GC hopes, but still fought to the very end in search of his first stage win of the race.
In the end his effort was not enough to better Bodnar, finishing in third place behind Kwiatkowski, but the performance secured his fourth Tour de France title, 54 seconds ahead of Rigoberto Uran.
Tour de France 2017, stage 20: Marseille to Marseille, 22.5km (ITT.)
1. Maciej Bodnar (Pol) Bora-Hansgrohe, in 28-15
2. Michal Kwiatkowski (Pol) Team Sky, at 1 sec
3. Christopher Froome (GBr) Team Sky, at 6 secs
4. Tony Martin (Ger) Katusha-Alpecin, at 14 secs
5. Daryl Impey (RSA) Orica-Scott, at 20 secs
6. Alberto Contador (Esp) Trek-Segafredo, at 21 secs
7. Nikias Arndt (Ger) Team Sunweb, at 28 secs
8. Rigoberto Uran (Col) Cannondale-Drapac, at 31 secs
9. Stefan Küng (Sui) BMC Racing, at 34 secs
10. Sylvain Chavanel (Fra) Direct Energie, at 37 secs
General classification after stage 20
1. Christopher Froome (GBr) Team Sky, in 83-55-16
2. Rigoberto Uran (Col) Cannondale-Drapac, at 54 secs
3. Romain Bardet (Fra) Ag2r La Mondiale, at 2-20
4. Mikel Landa (Esp) Team Sky, at 2-21
5. Fabio Aru (Ita) Astana, at 3-05
6. Daniel Martin (Irl) Quick-Step Floors, at 4-42
7. Simon Yates (GBr) Orica-Scott, at 6-14
8. Louis Meintjes (RSA) UAE Team Emirates, at 8-20
9. Alberto Contador (Esp) Trek-Segafredo, at 8-49
10. Warren Barguil (Fra) Team Sunweb, at 9-25
Road World Championships 2021: Five things to look out for in the men's road race
Van Aert the favourite and the next generation of Brits - keep your eye on these moments
By Stephen Puddicombe •
Tweets of the week: André Greipel gets a lesson from Alex Dowsett, a rabbit predicts the new world champion and more
Here's a selection of our favourite tweets from the last seven days
By Tim Bonville-Ginn •
Chris Froome and Philippe Gilbert save fan who fell down ravine on Tour de France stage 17
The incident occurred on the descent of the Col du Portet as the riders made their way back to the buses
By Jonny Long •
Chris Froome: 'I've got my running shoes in the car so I'm ready for Ventoux'
The four-time Tour de France champion looks back on the last time the race went up Mont Ventoux
By Jonny Long •
Mark Cavendish says ‘people will not understand mindset’ of Chris Froome as he chases Tour de France comeback
‘I can talk from personal experience, you can’t write somebody off’
By Alex Ballinger •
Chris Froome 'heading in the right direction' despite dark bruising on hip and chest
The four-time champion says he can never remember seeing so many injured riders in the peloton
By Jonny Long •
Tour de France bikes: Chris Froome’s custom Factor Ostro VAM
Magura disc-brake calipers feature alongside old favourites such as Osymetric chainrings and Lightweight Meilenstein wheels
By Stefan Abram •
Israel sports director questions whether the best-ever Chris Froome could compete with young stars of today
Israel Start-Up Nation say Froome didn't come into the Tour 100 per cent, but will improve by the third week, and will hopefully be the 'real Chris Froome' at this year's Vuelta a España
By Jonny Long •
Chris Froome finishes stage two of Tour de France despite injuries, Ineos Grenadiers riders lose more time
Tao Geoghegan Hart lost a big chunk of time for the second day running
By Chris Marshall-Bell •
Chris Froome passed fit to start stage two of Tour de France after evening in hospital
The Israel Start-Up Nation rider was caught up in the second of stage one's massive crashes
By Chris Marshall-Bell •