The #8 Toyota of Alonso, Kazuki Nakajima and Sebastien Buemi also became 2018-2019 World Endurance Champions after the sister car, the #7Toyota, was beset by problems in the final hour, including a puncture that denied them what had seemed like a certain victory.
Toyota and Alonso complete victory at Le Mans
Former F1 world champion Alonso was part of Toyota's winning team a year ago on his first outing at the event.
Alonso, 37, recognised luck had played a big part in completing an unprecedented Le Mans double in a single super-season.
"The main goal this weekend was to win the championship," the Spaniard, who won his Formula One titles with Renault in 2005 and 2006, told Eurosport television.
"I think car seven was quicker than us for 24 hours, they really deserved the victory but today the luck decided that we have to take the trophy.
"Luck sometimes plays an important part in motorsport and today we feel extremely lucky and maybe we don't deserve it but we take it," added the former Ferrari and McLaren driver who left Formula One last year.
"The world championship feels right at this moment."
The number eight crew had needed only a top-seven finish to be sure of the title, with the number seven car their sole rivals.
Alonso is trying to complete the triple crown of motorsport by winning the F1 drivers' title, Le Mans and the Indianapolis 500, a feat only achieved by England's Graham Hill, who died in a plane crash in 1975.
The number eight car crew took the lead with an hour to go with Nakajima driving the final stint and becoming the first Japanese to win the title.
Toyota's number seven TS050 hybrid car, crewed by Britain's Mike Conway, Japan's Kamui Kobayashi and Argentina's Jose Maria Lopez, led most of the way but suffered two late punctures and dropped to second in a one-two finish for the Japanese manufacturer.
Belgian Stoffel Vandoorne -- Alonso's former McLaren Formula One team mate -- finished third in his debut Le Mans with Russian team mates Vitaly Petrov and Mikhail Aleshin in the number 11 SMP Racing BR Engineering car.
Toyota 7 car sees Le Mans dream wrecked by mechanical problem