Federer, the second seed in Rome, stumbled towards the finish line in his third-round match against South African Kevin Anderson but recovered his poise in time to close out a 6-3 7-5 victory in 76 minutes.
The Swiss, making his 15th appearance at the Foro Italico still looking to break his duck, squandered a 5-2 double-break lead in the second set as the big-serving Anderson staged a fightback but Federer broke again in the 12th game before serving out at the third time of asking.
“It was so different, because it’s Kevin and his amazing serve,” said Federer, who will now meet Tomas Berdych on Friday for a place in the semi-finals after the Czech number one overcame a partisan crowd to beat home favourite Fabio Fognini 6-3 3-6 7-6 (7-2).
Eight-time champion Rafael Nadal produced a near-flawless performance to overcome giant American John Isner 6-4 6-4 in just 79 minutes in the opening match of the day.
Isner went into the contest having won 84 straight service games since being broken by Nadal in the fourth game of the third set of their Monte-Carlo third-round clash but the fourth seed committed just three unforced errors and won 90 per cent of points behind his first serve.
“In general, I think I played very well,” said Nadal, who will next meet Stan Wawrinka, a 7-6 (7/3) 6-4 winner over Austrian Dominic Thiem.
The 30-year-old Wawrinka, still searching for a return to his best form, took his chances in a tight match with Thiem, breaking once in the second set to claim victory in one hour and 38 minutes.
Seventh seed David Ferrer won an all-Spanish contest with Guillermo Garcia-Lopez 6-1 6-3 to set up a quarter-final meeting with David Goffin, who was given a walkover when Murray withdrew due to fatigue.
Murray wrote on Twitter: “I always feel bad after making decisions like this but my body is extremely tired and fatigued right now having played 10 matches in the last 12 days.”
Djokovic, who dropped a set in his opening match against Nicolas Almagro, came from behind to beat Brazilian Thomaz Bellucci in the night match.
Bellucci secured his only break point of the first set in the 11th game to lead 6-5 and duly served it out but Djokovic, who has never failed to reach the quarter-finals in all nine previous visits to Rome, fought back to win 5-7 6-2 6-3.
The world number now plays Kei Nishikori, who overcame Viktor Troicki 6-4 6-3.