Cristiano Ronaldo will have to navigate a play-off with Portugal to seal a spot at next year's World Cup after a last-gasp Aleksandar Mitrovic header gave Serbia a 2-1 win to see them top qualifying Group A and a place at Qatar 2022.
The victory saw Serbia take the group with 20 points, three more than second-placed Portugal who only needed a draw to finish top on goal difference and qualify but will now head into the March play-offs.
Half-time substitute Mitrovic beat home goalkeeper Rui Patricio with a downward header at the far post to spark wild celebrations on Serbia's bench after visiting captain Dusan Tadic had cancelled out an early Renato Sanches opener for Portugal.
Jubilant fans thronged central Belgrade, bringing traffic at the main Republic Square to a halt as they waved Serbian flags and hooted their car horns.
With Portugal's talismanic captain Ronaldo stifled, they produced little up front and midfielder Joao Palhinha conceded the home side were below par.
"We have to take responsibility because we had a poor game," he told Portugal's RTP television. "We just defended in the second half. Credit to Serbia, they played very well but we had the capacity to be on top.
"Everyone in the dressing room is disappointed but we have to look ahead to the playoffs now because we are more than good enough to be in the World Cup.
"You can't win all the time. Difficulties are part of life and this feeling should give us more strength."
Serbia coach Dragan Stojkovic threw Mitrovic on for Gudelj and his gamble to deploy an extra forward for a defensive midfielder paid off as the Fulham striker, his country's all-time top scorer with 44 goals in 69 appearances, delivered.
It seemed Portugal would hang on after Mitrovic headed inches wide in the 85th minute but the striker had the last laugh as he pulled away from his markers at the death to head home after Tadic's cross from the right.
Mitrovic, whose winner extended his national goalscoring record to 44 goals in 69 matches, said Serbia's confidence ahead of the game was vindicated by a bold performance.
"We came here to play football and having been the better side, we earned it all," he told Serbia's Nova television.
"We are reaping the rewards of hard work and the belief that we would be able to defy the odds and beat Portugal. We are overjoyed, for our country and the people first and foremost.