Anderson, a two-time Grand Slam runner-up, prevailed 7-6 (3) 4-6 6-3 in a contest which was just a minute short of three hours.
This was the third meeting between the pair – the score tied at 1-1 – and the South African had used a protected ranking to play after being sidelined by several injuries.
The first set was a see-saw affair with British star Edmund racing into a 2-0 lead before Anderson fought back.
Edmund then broke for a 4-2 lead and served for the first set at 5-3.
But Anderson hit back and, having trailed 3-1 in the tie-break, reeled off six successive points to take the first set.
Edmund fought back to level after breaking Anderson's serve in the fifth game of the second set.
Anderson had to call for a physio in the deciding set when 3-2 ahead, but broke to make it 5-3 and served out the final game to reach the last 32.
Qualifier Cameron Norrie lost 6-3 6-4 to American Reilly Opelka, who survived a break point against him in the final game.
Heather Watson suffered a second successive first-round defeat in the ladies' singles after her Top Seed Open loss to Jennifer Brady either this month.
Bernarda Pera won the first meeting between the two players 6-1 3-6 6-3 after staging a fine final-set comeback.
British number two Watson was a break up in the decider to lead the American left-hander 3-2.
But big-hitting Pera rattled off the final four games to win in one hour and 44 minutes and progress to the last 32.