Top seed Djokovic lost his bearings in the second set before beating Italy's Fabio Fognini 6-0 5-7 6-2.
"It was definitely a difficult challenge today," Serbian Djokovic said courtside after breaking the feisty Fognini in the fourth and eighth games of the third set to claim victory.
"Fabio played very well towards the end of the second set but it was all my fault," said the world number one, who squandered one match point in the 10th game of that set before being broken in the 11th when he netted a forehand.
"I had a very bad game at 4-2, made a couple of unforced errors, got him back in the match. Next thing you know we're one set all and a couple of tight games. I'm just happy to get through."
Djokovic, who had stormed through the opening set in just 19 minutes, wrapped up his fourth win in four matches against Fognini when the 36th-ranked Italian netted a backhand.
The Serb, a perfect 14-0 this year after winning the Australian Open in January and the Dubai Championships last week, will next meet Bulgarian Grigor Dimitrov, a 6-4 6-4 winner against Australia's Matthew Ebden.
"My confidence level is high obviously because of the run I had this year," Djokovic said. "Game-wise, everything works. I feel good about myself."
In other matches, American Mardy Fish made a triumphant return to the ATP Tour after being sidelined since last year's US Open because of a heart condition, battling past compatriot Bobby Reynolds 6-3 3-6 6-4.
The fact that he was able to fight back from a break down in the third set to seal the win was double cause for celebration.
Trailing 2-4 in the decisive set, the 31-year-old Fish won the last four games to book his place in the third round against eighth-seeded Jo-Wilfried Tsonga, the Frenchman having swept past James Blake 7-6 6-4.
"It's been a tough few months, for sure," said Fish, who was embraced at the net by qualifier Reynolds at the Indian Wells Tennis Garden after the match.
"You sort of feel like it was a win just to get back out there. There are a lot of people that have dealt with what I've dealt with and not come back," he told reporters.
"It's nice to just play, first and foremost, and then you get out there and you want to win. I certainly didn't expect to win so soon.
"I've been playing for a quite a while now as far as months are concerned but competitive matches, you can't duplicate those."
Fish had not played in a tournament since the US Open in September when he was forced to pull out before his fourth-round match against Roger Federer because of heart palpitations.
The American first felt a problem with his heartbeat before a Davis Cup match in February last year and the condition worsened in the following weeks.
At the Sony Ericsson Open in Miami last March, he woke up with his heart beating three times faster than normal and later said he had feared he would die.
Fish had an operation in May to correct a form of arrhythmia in his heart but repeatedly had to delay his return to the ATP circuit while he continued to recover due to health issues related to his surgery.
"For the first three months after the US Open, I had retired and non-retired in my head almost every week," said Fish, a winner of six ATP singles titles. "And there was a while where I was done.
"I had gotten it through my head that I was done when I was just trying to get my normal life back, just trying to have normalcy again.
"From what I have been through in the past six months, seven months, I hope to come out stronger. I know I'll be stronger. It's just nice to be out in the sun playing for something again."
Croatia's Marin Cilic overcame Spaniard Albert Ramos 7-6 6-2, Germany's Bjorn Phau scraped past Frenchman Jeremy Chardy 6-2 2-6 6-4 and Australian Marinko Matosevic brushed aside Argentina's Juan Monaco 7-5 6-0.
Also Nicolas Almagro swept past fellow Spaniard Daniel Gimeno-Traver 7-5 6-1 and Germany's Tommy Haas beat Spaniard Pablo Andujar 6-3 7-6.
- Sports & Recreation
- Fabio Fognini