Porsche sealed its 18th overall victory in the Le Mans 24 Hours as the leading Toyota, which had look nailed-on for the win, ground to a halt with less than four minutes remaining of a classic encounter at La Sarthe.
At the end of a gruelling race-long battle that saw the lead swap back and forth between the cars numerous times, Nakajima was set to bring the winning car across the finish line comfortably ahead of the #2 Porsche 919 Hybrid driven by Neel Jani, Marc Lieb and Romain Dumas.
Jani, taking over from Lieb for the drive to the finish, did his best to chase down Nakajima in the closing stages, the Swiss driver having already reduced the gap to the leading Toyota from over 1m10s to 30s at the start of the last stint.
The Swiss driver had to make a last-minute pitstop for two fresh tyres with 10 minutes left on the clock, allowing the #5 Toyota of Nakajima a clear run to the flag for a maiden Toyota win.
But with three minutes and 30 seconds left on the clock, the Japanese driver ground to a halt exiting the final chicane, allowing Jani and Porsche to sweep through to take an unlikely victory - the second in succession for the Weissach marque and the first ever for Jani and Lieb.
The #5 Toyota limped home in second, but was ultimately not classified for failing to make it back around to the chequered flag in time, promoting the #6 Toyota of Mike Conway, Stephane Sarrazin and Kamui Kobayashi to second.
The trio had led for much of the opening half of the race before dropping behind the sister #5 machine in the morning hours, but was ruled out of the lead battle when Kobayashi spun into the gravel just after the 20-hour mark.
That followed a skirmish with a backmarker that left the car with left-side bodywork damage.
The team therefore opted to bring in the car for a check of the cooling system that cost it 10 minutes, putting it out of overall contention, Sarrazin bringing home the car on the bottom step of the podium.
Audi suffers nightmare race
Following the demise of the #5, Audi took third and fourth places for its #8 and #7 R18 entries, which finished 14 and 17 laps down respectively after numerous visits to the garage throughout the race.
Among the most significant of these for the #8 car of Oliver Jarvis, Lucas di Grassi and Loic Duval was a 40-minute stint to have the front-right quarter suspension replaced in the 21st hour.
This was followed by a precautionary replacement of the front brake discs on the #7 R18 e-tron quattro for Andre Lotterer, Benoit Treluyer and Marcel Fassler, who had effectively been ruled out the fight for honours on Saturday evening by a broken turbocharger that needed changing.
The #1 Porsche entry driven by defending WEC champions Mark Webber, Timo Bernhard and Brendon Hartley was fifth, 38 laps down, unable to recover after its long early spell in the garage to fix a water leak.
In the LMP1-L division, the sole car running at the finish was the #12 Rebellion R-One of Nelson Piquet Jr, Nick Heidfeld and Nicola Prost, which ended up 54 laps down after being plagued by electrical issues in the opening stages.
Signatech-Alpine wins LMP2
Victory in the LMP2 division went to the #36 Signatech Alpine 460 of defending class champion Nicolas Lapierre and Le Mans rookies Gustavo Menezes and Stephane Richelmi.
The French team took control of the race during the night hours, helped by the #46 Thiriet by TDS Racing Oreca falling by wayside early in the morning.
That gave it a lead of a lap over the #26 G-Drive Oreca, which despite the best efforts of Rene Rast – who was able to get the car he shared with Will Stevens and Roman Rusinov back on the lead lap in the morning – ended up 2mXXs behind.
A further four laps down, third place in class went to the #37 BR01 of Vitaly Petrov, Viktor Shaitar and Kirill Ladygin, ahead of the #42 Strakka Gibson of Jonny Kane, Danny Watts and Nick Leventis.
Kane had passed Shaitar on track for the bottom step on the class podium during the morning, but Leventis was unable to sustain his teammate’s pace, the car ending up three laps down in P4.
The #44 Manor Oreca that led the race in the early stages was a high-profile late retirement as Matt Rao clattered into the barriers at the Porsche Curves after suffering front bodywork damage in a previous excursion at Indianapolis.
Ford makes history in GTE
In GTE Pro, Ford replicated its success of yesteryear on its much-vaunted comeback as the #68 Chip Ganassi Team USA entry of Dirk Muller, Joey Hand and Sebastien Bourdais took class honours, with the sister #69 entry of Ryan Briscoe, Richard Westbrook and Scott Dixon taking third.
The two Ford GTs were split by the #82 Ferrari, the Risi Competizione-entered car of Giancarlo Fisichella, Toni Vilander and Matteo Malucelli, which led for much of the morning before being passed by the quicker #68 car.
There was a further delay for the sole surviving 488 GTE as Vilander spun the car late in the 21st hour while chasing the lead Ford, Fisichella bringing home the car one minute down on Muller, who crossed the line to seal the Blue Oval’s historic win.
However, the #82 had been called in to serve a stop-and-go penalty in the closing stages to have its position indicator lights fixed, but did not do so, casting doubt over its result.
Fourth and best of the WEC-entered cars was the #66 Ford of Stefan Mucke, Olivier Pla and Billy Johnson, which was a lap down after electrical issues, followed by the two factory Aston Martins, the #95 leading home the #97.
In GTE-Am, the #62 Scuderia Corsa Ferrari 458 of Townsend Bell, Jeff Segal and Bill Sweedler took a straightforward victory, nearly a lap clear of the #83 AF Corse car of Emmanuel Collard, Rui Aguas and Francois Perrodo.
Bell set up the victory with a heroic stint in the night to catch and pass the #88 Porsche of Pat Long, David Heinemeier-Hansson and Khalid Al-Qubaisi, which fell to an eventual third.