The top-seeded Serb barely broke a sweat in the opening set but fell 7-5 in a second set tiebreak as the Spaniard upped his game on the stadium court at the Indian Wells Tennis Garden.
Champion here in 2008 and last year, Djokovic broke his opponent in the first game of the third set and also in the seventh before sealing victory on his first match point when Andujar hit a forehand service return wide.
"It's a fourth-round match and my opponent today is a really quality player who deserves to be at this stage of the tournament," a relieved Djokovic said in a courtside interview.
"In the end, I was lucky to get through some points. I am happy to get through to the next round."
The Serb will next face 12th seed