Italian Nardi, ranked 123 in the world, was originally eliminated in qualification but advanced to the main draw after another player withdrew.
He smashed 34 winners in a 6-4, 3-6, 6-3 victory over the 24-time Grand Slam champion, converting match point with an ace.
“It’s crazy,” said Nardi, the lowest-ranked player to upset Djokovic at the news Masters 1000 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 lost to eventual winner Jannik Sinner in the semi-finals of the Australian Open, has yet to win tournament this year.