James Anderson took three wickets as England battled back into contention, with South Africa ending the day 54 runs behind