Van Niekerk, at just two-hundredths of a second, added silver to the 400m gold medal he won on Tuesday.
Guliyev, who took up Turkish citizenship in 2011 and was cleared to compete for his adopted country two years later, clocked 20.09 seconds to hand Turkey its first ever world gold medal.
It was also the first time a Turkish male athlete had medalled.
Van Niekerk, at just two-hundredths of a second, added silver to the 400m gold medal he won on Tuesday, unable to catch Guliyev in his strong finish and plunge for the line.
Jereem Richards of Trinidad and Tobago claimed bronze in a photo finish from the South African.
"It's not a shock," insisted the 27-year-old Guliyev, who was draped in both Azeri and Turkish flags.
"I wanted to win and this year I thought it was possible and I made it. I believed in myself."
Guliyev added: "The going was so hard. When you race, you need to do your job. You run at your maximum.
"My first thought (after crossing the line) was 'am I first, second or third!' because when you run at your maximum, you only see straight -- not left or right."
There were a few boos from the packed-out London Stadium crowd as Guliyev streaked through the line ahead of Van Niekerk, thousands immediately upping and leaving rather than savouring the winning moment which ruined the South African's bid to match Michael Johnson, the US track legend who won the double at the 1995 Gothenburg worlds and went on to repeat the feat a year later in the Atlanta Olympics.
"It's been a tough week," Van Niekerk said. "I really feel I worked hard for tonight and I gave it my all. I have proven over and over I deserve what I have achieved.
"There are many people who don't think I deserve this.
"I work just as hard as every other competitor. I don't think I got the respect I deserved after the 400m but it's only the beginning and I will show my dominance."
With Usain Bolt, winner of the last four world titles, opting not to race the distance in his swansong season, the competition was lined up for a duel between Van Niekerk and Botswana's Isaac Makwala, the fastest sprinter over 200m this season.
The Botswanan rebounded from an IAAF ban on him competing in the 400m as he was placed under 48-hour quarantine in a bid to contain the highly contagious norovirus bug which has affected some athletes' hotels.
Makwala was forced to run an additional solo 200m qualifying time-trial before Wednesday's semi-finals and that extra exertion seemed to have taken its toll as the 30-year-old came in sixth (20.44).
"I've had one of the craziest championship journeys ever," said Makwala.
"I don't think I will ever face this again. I will always pray not to face this again."
"When I got into the race I was feeling good, but the last 50 metres I was feeling tired, the lactic acid came."
"I will leave the championships with my heart broken."
Guliyev was left with the last word, hailing the "best moment of my career".
"I was competing against some of the best athletes in the world, so it didn't bother me that the attention was on them," he said.
"Maybe at the next competition, everyone will look at me instead."