A hobbling Djokovic threw up courtside and received medical treatment multiple times, but still managed to last two sets; however, he was far from his best.
"I'm trying to pinch myself, is this real?" said Vacherot after the biggest win of his career.
"I know not many of you guys wanted me to win," he told the crowd.
"To have Novak on the other side of the court was, first of all, an invaluable experience for me.
"I have a hundred feelings right now."
Djokovic, 38, had said after his last match that he was concerned about his physical state, after battling through vomiting bouts, leg-injury scares and fatigue throughout the tournament.
However, the 24-time Grand Slam champion looked alert and seemed to be having a dream start when he broke in the first game.
But the satisfaction was short-lived as Vacherot broke back instantly.
The Serb former world number one began having issues in his left leg at the start of the seventh game, stopping to stretch multiple times and dropping to the ground at one point. He had to take an extended medical break, lying on his stomach shirtless as a physio attended to his back.
He got up but was still uncomfortable, hitting a ball against the wall in frustration after having to shake his leg out again.
With Djokovic clearly unable to move normally, Vacherot had an easy time breaking again in the eighth game, then fired two aces to hold the ninth and claim the set.
Djokovic received treatment again at the break, but was clearly still struggling in the second set.
In temperatures of 31 degrees Celsius and humidity levels of 62 per cent, Djokovic managed to hold the first game despite facing break point twice and falling to the ground again at one point.
Serving in the ninth game, he hit two double-faults in quick succession before recovering, only to ultimately be broken upon committing another.
Despite a late last-gasp effort from Djokovic, Vacherot held serve and his nerve to seal victory.
