Djokovic won on his second match point with an easy smash at the net.
"It was a great fight, almost four hours," Djokovic said of his win. "Bautista Agut, he's not going to hand you the win. You have to deserve it. You know, for me, not having so many matches in the last period, this is great. I mean, of course I don't want to play four, five hours every match, but I think it was a great test. I had to earn my victory."
The smash to end it wasn't his only one of the match.
After losing a point during the tiebreaker in the second set, Djokovic angrily whacked his racket into the clay. He regained his composure and broke the 13th-seeded Bautista Agut's serve early in the fourth set to take control.
"I was a bit unlucky not to capitalize on the second set," said Djokovic, who improved to 7-1 against Bautista Agut. "Maybe the match would be shorter, but at the same time, credit to him. I mean, he was better player in the third set, for example, and it was supposed to go his way ... he was serving for it. But that was a turning point."
Djokovic will next play another Spanish player, Fernando Verdasco.
Djokovic, who underwent right elbow surgery earlier this year, is the 20th-seeded player in Paris, his lowest Grand Slam seeding since the 2006 US Open. He arrived at Roland Garros with a 10-7 record this season.
He won the last of his 12 Grand Slam titles at Roland Garros two years ago.
The Associated Press contributed to this report.