Wagner, 30, who left South Africa to play provincial cricket in New Zealand a decade ago, took the wickets of JP Duminy, stand-in captain Faf du Plessis and swashbuckling Quinton de Kock to give the visitors the upper hand.
Trent Boult and Mitchell Santner grabbed two wickets each while Hashim Amla (53) and Temba Bavuma (46) top scored for South Africa.
"We bowled nicely from both ends with some green on the wicket and swing at the start. But we had to be patient and not get frustrated with the ball just passing the bat. We need credit for sticking at it," Boult told reporters afterwards, predicting that the wicket would become quicker on Saturday.
De Kock played a cavalier knock of 33 before being caught in the deep after an injudicious slog at Santner's spin.
Bavuma was more circumspect as he edged towards 50 only to be trapped lbw attempting a sweep.
Kagiso Rabada (14 not out) and Dale Steyn (two not out) will resume on Saturday.