Federer dropped the opening set against Swiss Davis Cup partner Stanislas Wawrinka and needed a tie-break to win the second before eventually easing to a 4-6 7-6 (4) 6-0 victory.
The world number one was outplayed for long periods by the 13th seed who buzzed around the court with confidence and invention in the opening two sets.
Wawrinka went into the match holding a terrible 1-11 record against his good friend but he troubled his more illustrious countryman right from the off with a varied gameplan that involved plenty of rushing to the net.
He needed just the one break in the opening set to take it 6-4, and despite going 3-1 down in the second set, he immediately hit back with a break of his own and showed composure on his serve for the rest of the set – even saving a set point while 4-5 down.
However, once he was edged out of the second set tie-break 7-4 he basically tanked the rest of the match as Federer won the final set without breaking sweat, sealing the win in one hour and 57 minutes, to set up a quarter-final date with 10th seed Marin Cilic who outlasted Fernando Verdasco 4-6 6-1 6-4.
Murray enjoyed a comfortable start to the defence of his title though with a 6-2 6-2 victory over Alexandr Dolgopolov.
The world number three received a bye in the first round and then enjoyed a walkover in the second but his lack of action did not show against his Ukrainian opponent who offered little resistance.
Murray wrapped up the match in just under 58 minutes with five breaks in total – two in the first set and three in the second.
Dolgopolov did break Murray's serve once in the second set to make it 2-2 but he produced an error-strewn performance and dropped the next four games to ensure a comfortable afternoon for Murray who had an impressive first serve percentage of 73 per cent.
Next up for the US Open champion will be unseeded Czech player Radek Stepanek who defeated John Isner 6-4 6-7(5) 6-3 in a gruelling contest that lasted nearly two and a half hours.
World number two Djokovic also secured his place in the quarter-finals with a 6-3 6-3 win over Feliciano Lopez.
The second seed, who was fresh off his fourth hard court title of the year in Beijing, secured an ATP World Tour-leading 67th match win of the year in very comfortable fashion.
Djokovic won a staggering 93 per cent of his first-serve points, and secured breaks at 5-3 in the first set, then at 2-1 in the second, as Lopez was never allowed to settle in the match.
The Serb has now won all five of his meetings with the 29th-ranked Spaniard, losing just a single set, and is 50-1 against non-top 10 players this year.
Djokovic will next take on Germany’s Tommy Haas in the quarter-finals after he demolished Janko Tipsarevic 6-2 6-1.
The other quarter-final will be between Jo-Wilfried Tsonga and Tomas Berdych after they enjoyed victories over Marcos Baghdatis and Sam Querrey respectively.
1-Roger Federer (Switzerland) beat 13-Stanislas Wawrinka (Switzerland) 4-6 7-6(4) 6-0
2-Novak Djokovic (Serbia) beat Feliciano Lopez (Spain) 6-3 6-3
3-Andy Murray (Britain) beat Alexandr Dolgopolov (Ukraine) 6-2 6-2
4-Tomas Berdych (Czech Republic) beat Sam Querrey (US) 6-2 6-7(3) 6-4
5-Jo-Wilfried Tsonga (France) beat Marcos Baghdatis (Cyprus) 6-2 7-6(2)
Tommy Haas (Germany) beat 6-Janko Tipsarevic (Serbia) 6-2 6-1
Radek Stepanek (Czech Republic) beat 8-John Isner (US) 6-4 6-7(5) 6-3
10-Marin Cilic (Croatia) beat Fernando Verdasco (Spain) 4-6 6-1 6-4
- Stanislas Wawrinka