The 24-year-old finished in 43.03 seconds, 0.15 quicker than the time Johnson clocked in Seville in 1999.
Grenada’s Kirani James, the London 2012 champion, finished 0.73 behind to take the silver medal, with American LaShawn Merritt in bronze.
“It was a massacre,” said Johnson, who won two Olympic 400m titles.
“Van Niekerk is so young, what else can he do? Can he go under 43 seconds? It is something I thought I could do, but never did.
“Usain Bolt will be retiring soon, this could be the next star.”
Van Niekerk, who won South Africa’s first gold medal of the Games, said: “I have dreamed of this since I was a kid.
“I believed it was possible. I am just glad things went my way. I thank Michael Johnson for setting such a great example for us. I just did my best.”
Van Niekerk’s performances in the heats gave little indication of what was to come.
He beat James and Merritt at the World Championships in Beijing last year, with all three going under 44 seconds, but qualified fifth fastest for the final in Rio.
James set off fast at the start of the race, but Van Niekerk, in lane eight, powered around the final bend to beat his previous personal best by 0.45 and win his first Olympic medal.
He is the first man to win an Olympic 400m title from lane eight.
Van Niekerk was still trackside doing interviews when Usain Bolt won 100m gold half an hour later, and revealed the Jamaican had predicted his success.
“I was over there for about two weeks training,” said Van Niekerk.
“Usain has been such a huge rock, inspiring me as an athlete. He told me back in Jamaica that ‘you will break the world record’. And he came to me after and said ‘I told you you could do it’.”
“I’m happy to be part of a race that made history,” said James. “We have put this sport on a pedestal.”
Great Britain’s Matthew Hudson-Smith, who finished last in 44.61, said: “It was just mental how quick that was.
“I thought I was gaining on them and then [Van Niekerk] kicked in the back straight and I thought, ‘What was that?'”