The big home hope looked in complete control, and unusually composed, at two sets and a break up but lost four straight games at the end of the third set.
He took his frustration out on his team sat in the stands and was close to
losing his cool completely but a break of serve in the 11th game of the fourth
set helped him clinch a 6-2 6-4 4-6 7-5 victory.
Kyrgios made no effort to excuse his behaviour, saying: "I was being a bit of a d***head to them.
"I apologised as soon as I went back into the locker room. They don't deserve that. They do a lot of things for me on and off the court. It's not acceptable from me."
The 24-year-old has been energised on the court by his drive to raise money for the wildfire relief efforts and it is clear just how much he wants to go deep into the tournament.
Kyrgios celebrated exuberantly at the end, and he said: "I definitely lost my way a little bit. He's a tough competitor, he knows how to win matches.
"I just tried to refocus. I could have gone to a very dark place in the fourth set but I somehow pulled it away.
"I put my head down, I told myself, 'Just cut the b******t and get to work'."
Both men, meanwhile, mocked the service tics of Rafael Nadal, who Kyrgios could meet in the fourth round.
The Aussie grabbed at his shorts and pretended to tuck hair behind his ears in imitation of Nadal after being given a time violation.
"I started my service motion," he said. "There wasn't any extracurricular activities I was doing before my serve to waste time."
Asked whose impression was better, Kyrgios replied: "I don't wear underwear, so probably Gilles'."
A meeting between Nadal and Kyrgios, who have clashed on and off the court over the past year, would be highly anticipated.
Nadal has not yet found top form and his match against Argentina's Federico Delbonis threatened to get complicated in the second set before he pulled away to win 6-3 7-6 (4) 6-1 after two and a half hours.
The top seed said: "I need to play better. Especially I need to convert the break points. I have been practising every day a little bit better. I am confident that I am going to play better because every day in the third set I have been able to show a good level of tennis."
The worst moment for Nadal came when he accidentally struck a ball girl in the head with a miscued shot.
The Spaniard went straight to check on the youngster, who thankfully was unhurt, giving her a peck on the cheek by way of consolation.
"I was so scared for her," he said. "She was a super brave girl."
Nadal will next face fellow Spaniard Pablo Carreno Busta while Kyrgios must get past Karen Khachanov, who won the final four points of a deciding tie-break in a 6-2 2-6 6-4 3-6 7-6 (8) victory over Mikael Ymer.
It was a day of five-set contests, with Stan Wawrinka, Dominic Thiem, Taylor Fritz and David Goffin also going the distance on their way to round three.
Things were much more comfortable for fourth seed Daniil Medvedev, whose biggest issue in a 7-5 6-1 6-3 victory over Pedro Martinez was a sudden nosebleed.
The Russian said: "(It) can happen to me sometimes. It doesn't usually happen during the match so I had to stop it. Usually it takes three, four minutes. I called the physio so he could help me to stop it. But it's nothing."
Seventh seed Alexander Zverev arrived in Melbourne out of form but is yet to drop a set while 17th seed Andrey Rublev extended his winning streak to 14 matches and qualifier Ernests Gulbis, whose ranking has dropped to 256, made the third round for the first time.