Djokovic, who ended a 54-week title drought with his 13th Grand Slam title at Wimbledon, will play the winner of a night match between five-time US Open champion Federer and John Millman.
Should Federer get through against the 55th-ranked Australian, he'll set up his earliest Grand Slam meeting with Djokovic since 2007, when Federer beat Djokovic to reach the Australian Open quarter-finals.
Djokovic, whose 6-6 record against Federer at Flushing Meadows includes victories over the Swiss great in the 2011 and 2015 finals, said he was relieved to get past 68th-ranked Sousa in straight sets as temperatures soared again.
"Very happy to get this one done in straight sets," said Djokovic, who left the court for a medical evaluation early in the third set but returned to wrap things up in exactly two hours.
Sousa, who got past 12th-seeded Pablo Carreno Busta and No. 17 Luca Pouille to become the first Portugese man to reach a Grand Slam last 16, was irked by the chair umpire's refusal to allow a line call challenge in the seventh game of the final set.
Djokovic broke him at love in the next game and served out the match without fuss.
"It was much more difficult than the score indicated," Djokovic said. "Credit to Joao -- he brought a lot of intensity to the court."
Kei Nishikori, runner-up in 2014, was also pleased to get through in three sets in blazing sunshine on Louis Armstrong Stadium.
After racing through the first two sets against Germany's Philipp Kohlschreiber he dropped his serve while serving for the match at 5-4 in the third, but managed to prevail 6-3, 6-2, 7-5.
"Man, really lucky to finish in three sets," Nishikori said. "It was very hot on the court even though it doesn't look too hot it's hit me."
Nishikori could end up fighting for a semi-final berth against Croatian Marin Cilic, who beat him in the 2014 final.
That remains Nishikori's best Grand Slam showing. After reaching a career-high fourth in the world in 2015 he slid down the rankings as a wrist injury sidelined him for six months, keeping him out of last year's US Open and eventually requiring surgery.
Seventh-seeded Cilic, who survived a five-set marathon against Australian teenager Alex de Minaur that went into the early hours of Sunday morning, faced 10th-ranked Belgian David Goffin later Monday.
Cilic is trying to reach the US Open quarter-finals for the fifth time, but he has lost 11 of his last 12 matches against top 10 opponents.