It was the 17th ton by Williamson, equalling Martin Crowe's New Zealand record, and featured in a commanding 190-run stand with Jeet Raval for the second wicket.
Raval's dismissal late in the day for 88 triggered a revival for South Africa as New Zealand slipped from 273 for one to 321 for four at stumps in reply to South Africa's 314.
Williamson was unbeaten on 148 with Mitchell Santner on 13.
New Zealand, battling to square the series which South Africa lead 1-0, took control on the third day after rain delayed the start.
Also Read
It was to be another 58 overs before a second wicket would fall as Williamson joined Raval to dictate the terms to a bowling attack toiling on a flat track.
South African skipper Faf du Plessis had identified Williamson's wicket as a key to beating New Zealand, and the number three batsman showed why as he moved quickly into attack mode, mindful of time lost because of the weather.
Williamson worked the ball to all parts of the ground including a six off Keshav Maharaj over the bowler's head.
The six off Philander made him the sixth and fastest New Zealander to reach 5,000 Test runs, seven innings quicker than the previous record set by Crowe.
When Williamson smacked part-timer Dean Elgar to the boundary for his hundred, he equalled Crowe's New Zealand record of 17 centuries but took 16 fewer Tests to get there.
While Williamson punished the bowling, Raval was impressively patient as he picked up ones and twos off the pace attack of Philander, Morkel and Kagiso Rabada.
Unlike Latham, whose edge had the wicketkeeper diving to his left to take a one-handed catch, the left-hander Raval had an inside edge which forced de Kock to dive right to take another one-handed catch down the leg side.
Rabada then accounted for Neil Broom (12) and Henry Nicholls (nought) in successive balls before Santner joined Williamson to guide New Zealand through to stumps.
For South Africa, Morkel has two for 74 and Rabada two for 83.
Disclaimer: No Business Standard Journalist was involved in creation of this content