Italian Nardi, ranked 123 in the world, had originally been knocked out in qualifying but reached the main draw after another player’s withdrawal.
He hit 34 winners in a 6-4 3-6 6-3 win over the 24-time Grand Slam champion, converting match point with an ace.
“It’s crazy,” said Nardi, the lowest-ranked player to beat Djokovic at ATP Masters 1,000 or Grand Slam level.
“I don’t know [how I held my nerve], I think it is a miracle, because I am a 20-year-old guy, and beating Novak.”
Djokovic, 36, who was beaten by eventual winner Jannik Sinner in the semi-finals of the Australian Open, is yet to win a tournament this year.
“No titles this year. That’s not something I’m used to,” said the Serb, who hit 17 winners but made nine unforced errors.