Djokovic trailed two sets to one and saved a break point in the fourth set before rallying to beat Serbian Davis Cup team-mate Viktor Troicki 6-3 3-6 2-6 7-5 6-3 in three hours 40 minutes.
The number three seed, who often has breathing difficulties in hot weather, understandably struggled as the temperature in New York approached 100 degrees, but dug deep to improve his career five-set record to 11-5.
Asked about finally getting some shade on the Arthur Ashe Stadium in the fifth set, Djokovic said: “Oh my God, it was a sleeping with my girlfriend kind of feeling!”
“Somebody from the stands was keep on saying ‘Hold on and try to hang in there’ and that’s exactly what I did.”
Troicki was left to rue missing out on a break point in the fourth set which would have given him a 4-1 lead with Djokovic looking out on his feet.
That seemed to galvanise the world number three into action and he immediately broke back to level at 3-3 and broke again in the 12th game to force a decider.
The 23-year-old no doubt relished the appearance of some much-needed shade on the Arthur Ashe Stadium, but still needed to recover from dropping his serve in the first game of the fifth set before eventually getting the better of world number 47 Troicki.
Djokovic will play German Philipp Petzschner in the second round and is 12/1 to go on and win the US Open.
Djokovic is a notorious slow starter in major tournaments so expect to see him recover in the next round. See the latest US open tennis betting markets here.