Sainz sat 4m47s adrift of de Villiers heading into the last stage, but rapidly brought down that deficit to just 26 seconds in the first 146km of running.
However, less than 10km from the finish line, an engine cooling tube on his MINI Cooper broke, ending the two-time World Rally championship’s charge in an instant.
Sainz’s troubles cleared the path for de Villiers to win the final stage of the rally, and with it take the overall victory for Toyota.
Sainz was classified a distant 12th in the 166km stage, but held on to second place in the overall standings – finishing 17m42s down on winner de Villiers.
Mathieu Serradori of Centuri Racing completed the overall podium spots, with Jakub Przygonski finishing fourth after towing the fellow MINI of Sainz to the finish line.
Stephene Peterhansel took fifth to secure the FIA Cross Country World Cup, benefitting from troubles of chief rival Nasser Al-Attiyah, who had led the rally for the first three legs until running into technical problems on Tuesday.
Two-time Formula 1 world champion Fernando Alonso finished 21st on his cross-country rally debut after posting the eighth quickest time in the final stage.
Alonso had shown top-10 pace throughout the five-day rally in his Toyota Hilux, but his work was undone by a suspension failure on day 3 – caused when he hit a ditch that was not marked in the roadbook.
Meanwhile, Andrew Short came on top in an inter-Husqvarna battle with Pablo Quintanilla to take the Moto honours.
Joan Barreda finished third for Honda, while KTM star Toby Price recovered to fourth after winning the final stage.