Both players battled out a tight first set as neither gave away their serve, leading to a tie-breaker where the South African managed to up the ante and secure the set with a 7-5 victory courtesy of a winner on his forehand.
The number 15 seed took the initiative in the second set as he secured an early break of the 28-year-old to take a 2-0 lead before he produced further quality tennis to break the Scot once more.
However, Murray fought back to bring the set back to 5-3 and had another break point which would have allowed him to serve to level, but Anderson fended off the threat and held out for the 6-3 win.
The third seed began the third set badly as Anderson secured an early break, but Murray levelled the scores in the next game and forged ahead with a break of his own. The South African came back into the set strongly and broke back to take it to a tie-breaker.
The British number one displayed his quality in the tie-breaker with an array of impressive groundstrokes to force mistakes from Anderson to take the set courtesy of 7-2 victory.
Both men battled ferociously in the fourth set, producing outstanding tennis to bring about another tie-breaker. The South African dominated proceedings as he fired a series of winners across the court to take a 6-0 lead.
On match point the 29-year-old fired a shot deep to the baseline that Murray could only guide into the net to hand Anderson a place in the quarters.
Anderson will now face Stanislas Wawrinka in the last eight of the competition.