The nine-time world champion, making his final guest appearance of the season with Citroen Racing, edged defending title holder Sébastien Ogier by 2.9sec in an intense finale to the four-day mixed surface event.

Ogier’s consolation was that he regained the championship lead by three points from Thierry Neuville with one round remaining. The Belgian was relegated from third to fourth, and missed out on crucial bonus points, after hitting a stone near the finish.

Loeb, who retired from full-time competition in 2012, last stood on the winners’ podium in Argentina in 2013

He lay third overnight but charged into the lead by winning Sunday’s opening two speed tests as an inspired tyre choice reaped rewards.

The asphalt roads dried quickly after overnight rain and the 44-year-old was the only front-running driver to gamble on Michelin’s hard compound tyres, which provided better grip than the softer option favoured by his rivals.

Loeb threw away vital seconds with a spin in the penultimate test to allow Ogier to close in his Ford Fiesta. He held on through the final 14.50km test for his ninth Spanish win.

“The information we had from the weather team was right. The roads were drying and I knew if I used hard tyres in these conditions I could be fast,” he said.

“To win after almost six years is incredible, but to do so in a battle like this, where you only discover after the finish line that you have won, is amazing. I never believed I would win again.”

Tyre choice errors early in the event cost Ogier dear, but this season’s remarkable title fight swung back in his favour when Neuville hit a stone close to the finish.

The impact broke his Hyundai i20’s right rear wheel and allowed Elfyn Evans, team-mate to Ogier, to snatch third and aid his colleague’s title bid. Evans ended 0.5sec clear of Neuville.

Spain’s Dani Sordo was a further 1.6sec behind in fifth. Meanwhile, early leader Ott Tänak recovered to sixth after yesterday’s puncture. The Estonian is 23 points adrift of Ogier and with a maximum 30 available at the last round, his hopes hang by a thread.

Overnight leader Jari-Matti Latvala remained second until he hit a barrier in the penultimate stage. That punctured his front left tyre and dropped nearly 50sec. He finished eighth.

The championship showdown takes place at Kennards Hire Rally Australia. The gravel event is based in Coffs Harbour on 15 – 18 November.