Novak Djokovic said talking to himself in the mirror when he was two sets down was the turning point as he beat Jannik Sinner to reach the Wimbledon semi-finals.
The top seed and defending champion, bidding for a fourth successive SW19 title and seventh overall, came through 5-7 2-6 6-3 6-2 6-2 on Centre Court.
Serb Djokovic, 35, will play Britain's Cameron Norrie next.
"He was the better player for the first two sets," Djokovic said.
"I went out and had a refresh, had a toilet break, I had a little pep talk to myself in the mirror, it's the truth.
"Sometimes in these circumstances when not much is happening positively for you, sometimes these things are necessary. A little break to try and regather the thoughts and reassemble."
Djokovic was given a huge scare by Italian 10th seed Sinner, who initially rose to the occasion as he tried to reach a Grand Slam semi-final for the first time.
However, the 20-year-old faded in the final three sets as Djokovic improved after an erratic and subdued opening.
The real Djokovic eventually emerges
There was no suggestion of the drama ahead when Djokovic moved 4-1 ahead in the first set and brought up a break point for 5-1, but his level suddenly dropped just as Sinner grew into the match.
Groundstrokes began to fly long and drop shots either flopped into the net or sat up for Sinner to put away as the Serb fell two sets behind, at risk of his first defeat at Wimbledon since retiring from the 2017 quarter-final against Tomas Berdych because of a shoulder injury.
It has been difficult to judge where Djokovic's game is this year as he did not play the Australian Open and the American hard-court swing because of his Covid-19 vaccine status.
Having lost to Rafael Nadal in the French Open quarter-finals, he did not play a grass-court warm-up tournament but had reached the last eight here for the loss of just one set.
Perhaps the lack of his usual matchplay had an effect here, and he showed little emotion as he dropped serve twice in both the first two sets and was thoroughly outplayed by the more aggressive Sinner.
After his toilet break at the end of the second set, a more recognisable Djokovic appeared. He began to step into the ball rather than scramble behind the baseline, and a break to love for 3-1 gave him a foothold in the match.
At 30-30 in the next game, Sinner netted a makeable volley and Djokovic engaged with the crowd for the first time, waving his arms and encouraging them to make more noise.
Sinner saved two set points at 5-2 down but Djokovic wrapped it up in the next game, dropping only five points on his serve in the third.
Two Sinner double faults set Djokovic on his way immediately in the fourth set and he then broke again as he moved 4-0 up. The Italian did become more competitive towards the end of the set, but he had a scare when his left foot slipped as he chased a volley.
He grabbed his ankle and was down for a while, but was fine to continue after Djokovic came round the net to check on his condition and helped him to his feet.
The crowd got behind Sinner and roared in encouragement when he held at the start of the final set, but a tentative volley and weak drop shot that both found the net gave Djokovic a break for 2-1.
There seemed little doubt now about the result and Djokovic duly moved on after a spectacular backhand cross-court winner, which left him lying flat on his chest, was followed by a wild drive volley from Sinner on match point.
Djokovic said his "pep talk" at the end of the second set was entirely "positive".
He added: "As negative and down as you feel on yourself in those moments, even though as fake as it looks or sounds to you, it really gives you an effect and support if you are trying to find the right and positive affirmations and tell it to yourself and kind of reanimate yourself in a way.
"So that's what I have done. I've done that after I lost two sets in finals of  Roland Garros against [Stefanos] Tsitsipas, and today it worked. It doesn't always work. It's not a guarantee it will always work."
Sinner falls short but shows top-level potential
Sinner has been seen for a while as one of the most talented young players in the men's game, although more recently there has been a greater focus on Carlos Alcaraz, whom he beat in four sets in the last 16 on Sunday.
He arrived at Wimbledon, where he had never previously won a match before this year, with little outward expectation, having retired from his fourth-round match at the French Open against Andrey Rublev with a knee injury. He then lost his only match at Eastbourne to Tommy Paul.
However, he had knocked out three-time Grand Slam champion Stan Wawrinka and John Isner before Alcaraz on his way to the last 16, where he faced the ultimate challenge of playing the 20-time Grand Slam champion.
Sinner made a nervous start, with seven unforced errors in the first five games before he narrowly avoided falling a double break behind.
When Djokovic's errors handed him the break back, he took that as his cue to go on the offensive, stepping inside the baseline and dictating rallies with flat groundstrokes into the corners.
Djokovic had to save a break point at 4-4 but could not resist next time around, Sinner hammering away a drop shot and then smacking a forehand out of reach to move 6-5 up before serving out the set.
He carried the momentum into the second, an over-the-shoulder backhand volley bringing huge cheers with a first break quickly following.
By now, Djokovic was under pressure every time he served and a successful challenge from a return that landed on the line gave the Italian daylight on the scoreboard, with four points in a row from 0-30 down ensuring a two-sets-to-love lead.
Ultimately he could not maintain that standard - or Djokovic did not allow him to - but Sinner showed he can mix it with the big boys when it matters most.
Of his opponent, Djokovic said: "I feel like Sinner, coming into the match, didn't have much to lose, but he had a lot to lose when he was two sets to love up. I could feel that mentally with him.
"So I'm sure he's going to get better as the time passes by, because he's a fantastic player and very mentally present, devoted, professional. Sure we are going to see a lot of him on the big stage."
Sinner said: "I was playing well, and he raised his level during the fourth, and I think the fifth I played in the right way, I just missed the final shots.
"I think I can be proud of what I have done here. Hopefully it can give me a lot of confidence."
- From teenage parties to rock 'n' roll-defining performance: Mick Jagger talks openly about his life in The Rolling Stones
- The Whistleblowers: The accounts of UN staff who reported their colleagues' alleged wrongdoings