The world No. 1 initially lost his cool when a stray backhand gifted Agut the first set, splintering his racket at the back of the court.
That was followed by the Serb ripping the neck of his shirt open after an attempted passing shot dropped into the net, giving Agut break point in the second set.
Djokovic received a time violation while changing into a new shirt, further incensing him and he was scathing in his criticism of umpire Carlos Bernardes after the match.
"He was the star of the show," Djokovic told reporters. "That's what he wanted to be today."
The 29-year-old, who has won in Shanghai three times, suggested fatigue played a part in his on-court outburst.
"There are definitely things that I need to regain from the emotional, mental point of view.
"So I guess I'm focusing on that more. It's a transition somewhere in between, maybe just exhausted by the amount of matches I have had in the last 15 to 20 months.
"Maybe all in all that's the cause of me feeling this way. I had to experience this sooner or later. I knew I could not go on playing at the highest level for so many years all the time."
Djokovic's first ever defeat to Agut opened the door for Andy Murray to close the gap at the top of the world rankings.
The world No. 2 beat France's Gilles Simon 6-4 6-3 to reach his fifth final of the year.
At the start of 2016, Murray set himself the target of reaching the top of the world rankings but admits, after the brilliant start Djokovic made to the season, that might now be out of reach.
"I said that I want to try to get to number one, but I'm still quite far away, so I'm not thinking about the number one ranking this week or right now," he said.
"I just want to finish this year as best as I can, it's been the most successful in my career.
"The last few months have been some of the most consistent I have been, so I just want to keep it going until the end of the year and finish as strong as possible."