Steve Clarke's side had to win on the night in order to finish third and salvage their top tier status with a regelation play-off match.
John McGinn gave them the perfect start in the third minute when his low right-footed finish sneaked into the back of the net.
Scotland's work was undone just before the hour mark when Kamil Piatkowski scored a stunning strike from the edge of the box into the top corner of the net.
However, the visitors stole all three points at the death as Robertson headed in a cross at the back post, sparking wild celebrations.
Victory means Scotland have finished third in League A Group 1 and three points ahead of Poland.
MORE ON INTERNATIONAL FOOTBALL
Roy Keane gives hilariously blunt response to Ian Wright's I'm a Celebrity request
Poland captain refuses to apologise for controversial Cristiano Ronaldo photo
Portugal finished top of the standings with four wins from six ahead of Croatia, with whom they drew 1-1 on Monday night.
The draw for the Nations League play-offs will be conducted on Friday with matches to be played on March 20 and 23 next year.
Scotland's results in the November international break mark a huge improvement from their previous form.
From the beginning of Euro 2024 until the middle of October, they went on a winless run of seven matches.
Most read in Football
The extreme lengths Arsenal went to to hide Martin Odegaard's injury are revealed
Liverpool cult hero exiled at Serie A giants forced to stay due to tax reasons
How Man United could line up against Ipswich as Amorim to drop three stars in first game
Jordan blasts loophole that saw Bentancur get banned but Fernandez escape punishment
This included five defeats, three of which came in the Nations League as their hopes of staying in League A became slimmer.
A 0-0 draw against Portugal offered them a lifeline before they beat ten-man Croatia 1-0 on Friday night.
Robertson's late goal has proven decisive for Scotland and spared them of relegation into League B by finishing bottom.
The Liverpool left-back is the first Scotsman to score a winning goal after 90 minutes since Scott McTominay in October 2021 against Israel in their 2022 World Cup qualifying match.
Monday night's dramatic match is the last they'll play until March when they contest their play-off matches against a League B runner-up.
Scotland's attention will then turn to qualifying for the 2026 World Cup, and they currently look set to be in pot three for the draw on December 13.