The 27-year-old Briton returned sharply and drew the 2.03-metre (6-foot-8) Anderson into rallies to impose his game on the Wimbledon grass where he is on a run of 17 successive victories.
Anderson, a career-high 18th in the world, broke serve only once, after rain forced a pause for the Centre Court roof to be closed with Murray 3-0 up in the second set.
He upped his game in the third set to force a tense tiebreak and even had a set point before the Scot won three points in a row to reach his seventh successive Wimbledon quarter-finals.
"When it was outdoors I played very well and was in a good position but when we came indoors he was striking the ball better and serving better and I was dropping shorter," Murray told reporters.
"That meant there was a lot more running at the end because he was playing very well."
It was the toughest match of the tournament for Murray who had dropped only 19 games on his way to the fourth round.
The champion started in relaxed style, breaking Anderson's booming serve in the third game and wrapping up the opening set in 43 minutes.
Looking supremely comfortable on the turf where he also won Olympic gold in 2012, Murray broke the South African twice early in the second set but the rain started to fall and organisers decided to close the roof.
The Scot, who always prefers playing in the elements, dropped his serve and two games later wobbled again to offer Anderson another break point.
Murray saved it but Anderson found a new confidence which he took into the third set, firing his 76th ace of the tournament to earn set point.
The ice-cool Murray replied with a big serve, forced an error to earn match point and produced a backhand winner to progress to the last eight to the delight of a noisy crowd.
"I am trying to stay concentrated on the court and I don't worry about everything else that's happening outside but when you play in front of a big crowd like this you raise your intensity and it helps you in a big way," said the holder.
Murray next meets 11th seed Grigor Dimitrov of Bulgaria for a place in the semi-finals.
- Sports & Recreation