The Toyota #7, driven by Mike Conway, Kamui Kobayashi and Jose Maria Lopez, was in the lead and on course for victory only to suffer a puncture with 62 minutes left on the clock.
Entering the closing stages the #8 car was over a lap behind the other Toyota hybrid, before lady luck intervened to gift them the advantage.
Nakajima went on to take the chequered flag to seal back-to-back Le Man's 24 Hours for himself, Buemi and Alonso, ahead of the sticken #8 car. With the win, the trio also wrapped up the World Endurance Championship title.
Alonso's second Le Mans 24 Hours trophy will join his two Formula One trophies in the cabinet.
A Toyota victory was all but assured this year, as it was in 2018, with the Japanese outfit the only manufacturer on the grid after Porsche and Audi pulled out.
A distant third was the private entry SMP entry driven by Vitaly Petrov, Mikhail Aleshin and Stoffel Vandoorne.
LMP2, GTE Pro, GTE Am
In the second prototype class, Signatech-Alpine also made it two in a row with Nicolas Lapierre, Andre Negrao and Pierre Thiriet, who also secured the LMP2 WEC title.
The GTE Pro category was won by the Ferrari of James Calado, Alessandro Pier Guidi and Daniel Serra to grand the Italian outfit their first win since 2014.
Amateur honours in GTE Am went to Keating Motorsports' Ford GT, driven by Ben Keating, Jeroen Bleekemolen and Felipe Fraga.