Andy Murray came back from a set down to beat qualifier Christopher O'Connell 6-7 (4-7) 6-3 7-5 at the Dubai Duty Free Tennis Championship.
The victory comes a week after Murray suffered one of the heaviest defeats of his career - 6-0 6-1- against Roberto Bautista Agut in Doha.
He will now face either Alejandro Davidovich Fokina or the world No 10 Jannik Sinner in the round of 16 in Dubai.
"I enjoyed the result," the Brit said on court after. "What went on in the middle was not so easy [to enjoy].
"I was very frustrated early on in the match; I couldn't quite find my game and he was dictating quite a lot of the rallies. I started to a little bit better as the match went on, which helped me a lot. I just managed to tough it out in the end.
"I've spoken to a lot of ex-players that say keep playing as long as you can because nothing will replace it.
"Obviously, some have regretted maybe stopping a little bit too soon. I still feel that I can compete at the highest level - it's not easy obviously. Physically, it's very challenging for me but winning matches like that is very satisfying."
The Scot cut a frustrated figure as he threw his racket to the floor after he was easily passed to give O'Connell, ranked 158, two break points at 4-4 in the first set.
He saved the first, but the racket hit the deck again as he punched a forehand wide to hand his opponent the break.
It seemed to provide the spark Murray needed, though, as he bounced back immediately by forcing two break points and converted the second to level the set.
However, the 34-year-old was unable to take advantage of a mini-break in the tie-break and the racket was flying once more as he gave up the opening set after a 68-minute toil.
A break to love at the start of the second improved Murray's mood and he dropped just five points on serve on his way to levelling the match.
The three-time Grand Slam champion had to dig deep to get out of trouble at 4-4 in the decider, saving four break points to stay afloat.
A stunning reach to pass O'Connell down the line brought about three match points and got the crowd to their feet. Murray converted the second to complete his marathon victory in just under three hours.