Controversial Australian Nick Kyrgios snapped “that’s just crap!” at the umpire on Wednesday as he earned his third code violation in a week when he smashed away a loose ball and nearly hit a line judge.

Kyrgios, 20, was left fuming by the decision at the climax of the second set as he slumped from a dominant start to a 1-6, 6-4, 6-4 defeat by Kei Nishikori in the Shanghai Masters second round.

Kyrgios also picked up a code violation for yelling “f***ing surface!” in the first round and was later fined $2,066 for the audible obscenity, as he veers dangerously close to triggering a four-week ban.

The Australian was handed a suspended ban in August for making a sexual slur during a Rogers Cup match about the girlfriend of his opponent at the time, Stan Wawrinka.

He will have to serve the ban if he picks up $6,885 in fines before February 24. Tennis officials will review the latest incident before deciding whether they will fine Kyrgios again.

World number one Novak Djokovic later said “patience is … a virtue” for Kyrgios, suggesting that Nishikori’s experience and focus had helped him win.

“I think Nick has to learn from these kind of matches, listen to the advice of more experienced people, especially from his country, Pat Rafter, Rod Laver, all the greats who have made the history of this sport,” he said.

“I’m sure they know, they understand the kind of mental challenges he’s facing. They understand what it takes. He needs to try to really work on it, getting mentally stronger.”