Fulham striker Mitrovic stepped off the bench to head home Dusan Tadic’s cross as Serbia hit back from behind to finish top of Group A.
Portugal made the ideal start when Renato Sanches blasted them into an early lead, but Tadic equalised before half-time and Mitrovic’s downward header won it in the dying moments.
Spain also left it late to seal their place at a 12th consecutive World Cup finals as Alvaro Morata’s late goal sank Sweden 1-0 in Seville.
Luis Enrique’s side needed a point to secure top spot in Group B, while Sweden, who needed victory to leapfrog them, will head to the play-offs.
Croatia, World Cup runners-up in 2018, clinched a place at next year’s finals in another winner-takes-all clash after Fedor Kudryashov’s late own goal sealed a 1-0 win against Russia.
Russia would have finished top of Group H had they held on for a point, but Kudryashov turned a cross into his own net in the 81st minute to leave Croatia top on 23 points, one ahead of Russia who face the play-offs.
Republic of Ireland won 3-0 in Luxembourg to extend their unbeaten run to five matches as they finished third in Group A.
Luxembourg had a second-half goal disallowed with the score locked at 0-0 before the Republic finished strongly with goals from Shane Duffy, Chiedozie Ogbene and Callum Robinson.
Germany who booked their place in Qatar with two games to go, extended their winning run under head coach Hansi Flick to seven matches by beating Armenia 4-1 in Yerevan.
Manchester City midfielder Ilkay Gundogan’s double, which included a first-half penalty, plus goals from Kai Havertz and Jonas Hofmann ensured Germany took 27 points from a possible 30 in Group J.
North Macedonia secured second spot behind Germany for a play-off place as their 3-1 home win against Iceland meant they finished one point clear of Romania.
Former Leeds defender Ezgjan Alioski gave the Macedonians an early lead and although Jon Dagur Thorsteinsson equalised early in the second half, Eljif Elmas struck either side of Isak Bergmann Johannesson’s dismissal.
Romania’s 2-0 win in Liechtenstein, courtesy of goals from Dennis Man and Nicusor Bancu, was not enough and they finished a point behind North Macedonia in third.
Slovakia finished in third place behind Russia in Group H after cruising to a 6-0 win in Malta, who had two players sent off.
Cologne midfielder Ondrej Duda scored a hat-trick and Albert Rusnak fired a double, while defender Vernon De Marco was also on target for Slovakia, who played with nine men for 40 minutes.
Malta midfielders Ryan Camenzuli and Teddy Teuma were both sent off for two yellow-card offences within five minutes of the second half.
Slovenia finished fourth, level on points with Slovakia, after beating Cyprus 2-1 in Ljubljana and Greece secured third place in Group B after drawing 1-1 with Kosovo in Athens.