Swiss great Federer was forced to grind all the way by his recent training partner Evans, with the 30-year-old from Birmingham even saving a match point.
But 39-year-old Federer was not to be denied victory on his big return, having fought off two knee surgeries to return to ATP tour action.
The 20-time Grand Slam champion had not played since his straight-sets defeat to Novak Djokovic in the 2020 Australian Open.
Federer mixed signs of rust with moments of magic, eventually just pulling home to book a quarter-final meeting with Georgia’s Nikoloz Basilashvili.
The three-time Qatar champion was handed a bye to the second round and a clash with Evans, who battled past French veteran Jeremy Chardy in the opening round.
Evans, 30, had lost all three of his previous career meetings with Federer but had taken a set each time and was banking on being a different proposition due to his improvement during Federer’s time away.
Federer showed few signs of rust in an entertaining opening set in which neither player gave his opponent much of a chance behind his respective first serve.
Pushed into a tie-break, it looked like the Swiss star who would falter first, a pair of uncharacteristic errors helping Evans win four points in a row to establish a 4-2 lead.
But the favourite proved he had lost none of his nerve, fighting back to level then taking advantage of his third set point opportunity with a sweeping backhand pass down the line to take the tie-break 10-8.
Evans looked a little more wobbly on his own serve at the start of the second set but managed to survive and pounced on a series of errors from Federer in the fourth game of the set, seizing his first break-point opportunity to go 3-1 in front.
Federer rallied but Evans proved equal to the challenge, looking confident from the back of the court as he served out to take the second set 6-3 and take the match into a decider.
Evans dug out a fine service hold to make it 3-3 in the final set, before Federer fended off two break points in the next game.
Federer forced a match point with Evans serving to stay in the contest, only for the Brit to hold under major pressure and continue the intriguing battle.
At the last however, Federer was able to pull away – breaking Evans to seal the set and the match.