Williams was on the ropes in the 12th game but she saved three match points to force the decider.
The seven-time Grand Slam champion, her right arm bandaged and her serve speed down, surrendered the first set in just 20 minutes and was quickly down a break at 3-1 in the second.
"I definitely wasn't able to do everything I wanted to," she said. "Took me some time to kind of get my head around that.
"You have to get disciplined and just try to deal with what's at hand and try to use the tools you have on this particular day," said Williams, who did so with a vengeance.
She broke Jankovic twice to take a 5-4 lead in the second set before the Serb veteran, like Williams a former world number one, broke in the 10th game to pull level at 5-5.
Serving to save the match, Williams was on the ropes in the 12th game but she saved three match points to force the decider.
Once she came through it, she ran away with the third, buoyed by an enthusiastic crowd.
"It ain't over til it's over," she told her ecstatic fans of her determination to stick with it until the end. "And I didn't see no fat lady singing."
Williams next faces Czech Lucie Safarova, a 4-6, 6-4, 6-1 winner over American Coco Vandeweghe.
Safarova denied Vandeweghe a chance to avenge her semi-final loss to Williams at the Australian Open, where Williams fell in the championship match to her sister Serena.
Jankovic, meanwhile, could only regret her missed opportunities, especially her first match point that Williams saved with a volley winner.
"When she was at the net I was supposed to play that cross forehand but I played down the line and right to her and she made a winner," Jankovic said. "I had everything under control and I just let it slip away."
There was no such drama for second-seeded Angelique Kerber, who raced into the third round with a 6-2, 6-1 victory over fellow German Andrea Petkovic.
Kerber, who is assured of reclaiming the number one world ranking when the tournament ends thanks to Serena Williams' injury withdrawal, reversed a run of poor fortune in the California desert, where she hadn't made it out of her tournament opener since 2011.
"Of course, it was not so easy to play against her, we know each other very long," Kerber said.
"I was trying today just to focus more on my side of the tennis court. Just being focused on my game, because I think the last three years I lose here in the first round, so that was also something in my mind that I would like to change this year and just go through it."
Kerber next faces France's Pauline Parmentier, who ousted 27th-seeded Yulia Putintseva of Kazakhstan 6-2, 6-3.
Women's fourth-seed Simona Halep of Romania cruised through her opener, downing Croatian wild card Donna Vekic 6-4, 6-1.
Sixth-seeded Agnieszka Radwanska beat Spain's Sara Sorribes 6-3, 6-4 and ninth-seeded American Madison Keys made a successful return to competition with a 6-1, 7-5 victory over Colombian Mariana Duque.
Keys was playing in her first match of 2017 after missing two months in the wake of left wrist surgery.
"It felt really good," Keys said. "I really, really missed competing and being able to go out there and get a win on top of it was amazing."