The 2011 champion won 6-3, 4-6, 6-4, 6-3 last night to set-up a clash against Spanish veteran Feliciano Lopez in what will also be his ninth US Open last-eight place in a row.
Djokovic gave up a 4-2 lead in the second set and saw an early break clawed back in the fourth by the 23rd seeded Agut, a former junior footballer with Villarreal in Spain.
The Serb was also broken when serving for the match at 5-2 as Agut unleashed a barrage of deep, murderous forehands before steadying himself to claim his 60th win of the year.
"I had a couple of points to break for 5-2 in the second set but I didn't capitalise and the match turned around.
Also Read
"He made me work for it -- there were no free points."
Lopez, 33, reached his first US Open quarter-final at the 14th attempt with a 6-3, 7-6 (7/5), 6-1 win over Italy's Fabio Fognini, the conqueror of Rafael Nadal in the previous round.
"Lopez is not the typical Spanish player. He comes into the net on first and second serve. He serves and volleys, uses a lot of slice," said Djokovic.
The Spanish left-hander has only ever taken one set off Djokovic and that was in their first meeting at the 2007 Australian Open.
"I will be 34 in September so it's a great feeling to be playing like this and reaching my first US Open quarter-final," he said.
"When Novak plays good, you don't know what to do to be honest. He has no weaknesses in his game."
Lopez had put out 10th seed Milos Raonic in the third round after having been just four points away from defeat against Mardy Fish in the second round.