Guliyev matched Van Niekerk stride for stride and won the 200m title by lunging at the line just ahead of the favoured South African. Jereem Richards of Trinidad and Tobago took bronze, while Makwala faded down the stretch and finished sixth.
It was all too much for Van Niekerk after the race as he broke down in tears during an interview with the BBC.
Van Niekerk, who had won the 400m earlier in the week, took a swipe at people who he felt have belittled his achievements.
"There are many people who don't think I deserve this," said the 25-year-old, who produced the performance of the Olympics last year breaking the 400m world record in winning gold.
"I work just as hard as every other competitor. I don't think I got the respect I deserved after the 400m (winning the world gold) but it's only the beginning and I will show my dominance."
Botswana's Makwala, who took a unique route to the final, finally ran out of steam. He had originally been scratched from the event on medical grounds, only to get a last-minute reprieve.
He booked his spot in the semis after a solo time trial in cold and wet conditions on Wednesday and then finished second in his semi, ensuring him the status of fan favourite for the final.
Makwala, at the end of the saga that started with a stomach virus early in the week followed by a forced quarantine and belated entry in the 200 heats, failed to sustain the early pace and quickly fell out of contention. "The last 50m I was feeling tired. The lactic came," Makwala said. "I've had one of the craziest championship journeys ever."
As Guliyev's win was confirmed after a thrilling finish to the 200m, some boos rang out and thousands of spectators couldn't make the exit quickly enough.
Guliyev held his hands over his mouth in sheer disbelief after the slow race - the slowest final since 2003.
"It didn't bother me the attention was on them," Guliyev said. "Maybe at the next competition, everyone will look at me instead."
The 27-year-old Azerbaijan-born sprinter, who became a Turkish citizen in 2011, then draped himself in both the Turkish and Azeri flags as he performed his lap of honour.
"It's not a shock. I wanted to win and this year I thought it was possible and I made it," said Guliyev. "Yes I believed in myself."
In the first 200m final without Usain Bolt since 2009, it was wide open from the start.
Guliyev had the second-slowest start of the eight finalists but he quickly surged among the leaders. Van Niekerk was slightly ahead coming off the bend but could not make his fluent stride count as Guliyev stuck with him all the way.