Murray lost an entertaining first set in a tie-break but bounced back to force a decider, winning the second set 6-2 as Fognini appeared to lose focus, smashing a ball into the stands and throwing a racket at his chair after allowing the Brit to break his serve twice in the set.
A tight third set burst wide open with three consecutive breaks of serve from 4-4 onwards and Murray served for the match at 5-4, at which point both players allowed their tempers to get the better of them.
'The younger generation has taken over' - Becker hails 'Dame Emma Raducanu'
Initially, Murray was frustrated at umpire Fergus Murphy for failing to stop the match due to rain, having been told by the official that he could "hear your shoes squeaking so there can't be that much moisture".
He then turned his anger on the powder key that is Fognini after the Italian appeared to shout while Murray was putting away a volley.
He told Murray not to complain, to which the former world No 1 promptly did, appealing to the umpire to enforce some sort of order.
"He shouts and then tells me don't look at me," Murray said.
"He just shouted in the middle of the point."
Andy Murray - Masters 1000 - Shanghai vs Fabio Fognini
Image credit: Getty Images
During a subsequent changeover while Murray was preparing to serve out the match for a second time at 6-5 up in the third set, he shouted across to Fognini "shut up".
Murray said: "You say the same to everyone.
"Mate, you say the same to everyone no matter who you're playing."
Murray was looking to continue his return to fitness having beating Juan Ignacio Londero in the first round of the Shanghai Masters, his first 1000-level victory since May 2017.
Victory over the world No 12 would have been the most significant win of his comeback so far since returning to singles over the summer.
However, it was not to be as the fiery Italian took the final tie-break 7-2 to seal a 7-6, 2-6, 7-6 victory and a place in the third round.
Murray shocked by world No 158 Safiullin in Rennes
Murray takes wildcard into Moselle Open in Metz