FERRARI won the 24 Hours of Le Mans for the second year in a row Sunday after a tight and tense battle with Toyota to the finish of the 92nd edition of the endurance race.

Almost out of fuel and on a wet track, Denmark’s Nicklas Nielsen took the chequered flag in the number 50 499P hypercar shared with Italian Antonio Fuoco and Spaniard Miguel Molina over 311 laps of the Sarthe circuit.

The car’s fuel gauge was registering around 2% at the finish.

The seven Toyota GR010 hybrid of Argentine Jose Maria Lopez — a late stand-in after Briton Mike Conway was injured in a cycling accident — Japan’s Kamui Kobayashi and Dutch driver Nyck de Vries finished 14.221 seconds behind after starting 23rd.

Ferrari’s winning crew from a year ago — Italians Alessandro Pier Guidi, Antonio Giovinazzi and Britain’s James Calado — finished third in the 51 car on a day of drizzle and overcast skies.

Last year’s comeback win was the Italian marque’s first overall victory at Le Mans in 58 years.

“The worst for me was when they asked me to go slower because that’s usually where the mistakes happen,” Mr. Nielsen told Eurosport television after saving fuel to the finish. “The last lap was so long. They kept me updated on the gap basically all the stint so it was just about managing the gap to the car in P2 (second), but then it obviously was a very long stint… but we did it.”

All three drivers of the 50 car were first-time overall winners but the outcome remained open right to the end in a race with a safety car period lasting more than four hours during the night.

“We were waiting for this moment since one year,” said Mr. Fuoco, who took pole last year but ended up fifth. “At the end we won it and we are just super-happy.”

There was drama with more than an hour remaining when the car’s right-side door flapped open, forcing a pitstop — which later played into Ferrari’s hands with the car now on a different fuel strategy to rivals.

Toyota’s challenge was slowed by Mr. Lopez spinning at the Dunlop Curve, losing precious time and undoing the Argentine’s earlier good work. With 30 minutes remaining, and a 30-second gap to the leader, Toyota effectively conceded defeat and told Mr. Lopez to bring the car home in second place.

Ferrari had looked good from the start, with the two factory cars joined by the number 83 AF Corse customer team entry driven by Poland’s Robert Kubica, Israeli Robert Shwartzman and China’s Yifei Ye.

The 83 car, which had led on Saturday, retired four hours from the end with technical issues.

Porsche Penske finished fourth with the pole-sitting number six car driven by Laurens Vanthoor, Kevin Estre and Andre Lotterer. Toyota’s number eight car, driven by former winners Sebastien Buemi, Brendon Hartley and Ryo Hirakawa, took fifth place.

Two-time IndyCar champion Alex Palou finished seventh in the number two Cadillac. BMW and Renault-owned Alpine were out of the running by midnight, with the latter’s number 35 catching fire at Arnage after nearly five hours of racing and the 36 car retiring with engine trouble.

The number 22 United Autosports Oreca entry of Britain’s Oliver Jarvis with Americans Bijoy Garg and Nolan Siegel won the second-tier LMP2 category.

Italian MotoGP great and Le Mans rookie Valentino Rossi failed to go the distance, his LMGT3 BMW crashing into the wall shortly after midnight with team mate Ahmad Al Harty driving. Reuters