The Serb came back from two sets to one down to win 5-7 6-3 3-6 6-1 6-1.
Djokovic, 30, finished strongly despite making 55 unforced errors and arguing with umpire Carlos Ramos over a conduct warning.
The second seed goes on to face Spain's Albert Ramos-Vinolas, who beat France's Lucas Pouille.
The presence of new coach Andre Agassi has yet to inspire Djokovic to rediscover the form that made him a seemingly untouchable world number one this time last year.
An erratic performance saw the 12-time Grand Slam champion hit 21 errors in relinquishing a 4-1 lead in the first set.
However, Agassi's unexpected arrival midway through the second set apparently inspired Djokovic to a break of serve.
"I was focused on the screen and I saw obviously people reacting when he arrived," said the Serb.
"He was not supposed to be here today, because we have finished yesterday with our in-person collaboration here in Paris.
"I appreciate that. I respect that very much that he managed to do things and move his commitments around so he could come and watch."
That late break in the second appeared to have settled the world number two, but Schwartzman - playing his first ever third-round match at a Grand Slam - was his equal throughout the third.
The 5ft 7in Argentine then broke serve for a 5-3 lead and remarkably recovered from 0-40 to serve out the set.
With the crowd now excited by the prospect of an upset, Djokovic finally took a firm grip on the match by quickening the pace and shortening the rallies.
It was not plain sailing, however, and despite racing into a 4-0 lead in the fourth set, Djokovic became embroiled in a row with umpire Ramos after receiving two warnings in a game - one of slow play, the second for unsportsmanlike conduct.
Clearly annoyed, the champion retained his focus on the job in hand and reeled off 12 of the last 14 games as dark clouds above threatened to delay his progress.
"Playing a five-setter at this stage is good," added Djokovic.
"I enjoyed playing, really, even though of course at times I was not playing my best, especially for first three sets, but fourth and fifth sets went completely my way."
Defending champion Novak Djokovic survived a third-round scare at the French Open to beat unseeded Argentine Diego Schwartzman in five sets.