Ahead of the last stage, a 17-km time trial in Verona, the 29-year-old was fourth overall, but he showed his sprinting skills to overtake Spain's Mikel Landa to make it to the podium.
Competing for Jumbo Visma team from the Netherlands, Roglič finished the time trial in 22 minutes and 33 seconds to miss his third win in time trials at this year's Giro D'Italia by 26 seconds.
He was the 10th fastest racer today, beating Landa (Movistar) by 31 seconds for the first podium finish at the Grand Tour races (Giro d'Italia, Tour de France and Vuelta a Espana) for Slovenian cyclists.
The race totalling 3,547 km was won by Richard Carapaz of Equador (Movistar) ahead of Italian Vincenzo Nibali (Bahrain Merida). He conceded 49 seconds to Nibali in the last stage to win with an advantage of 1 minute and 5 seconds.
The podium finish for the former ski jumper comes after Roglič finished fourth overall at last year's Tour de France.
The only Slovenian who previously managed to make it to the top ten in Italy was Tadej Valjavec, who was 9th in 2004.
"It's funny to think that a small Slovenian can come to Giro and compete with the best," Roglič told Slovenian reporters in Verona Arena after the race. He added that the podium finish was like a win to him.
"I'm proud and happy," said Roglič, adding that "it is very nice to stand on the podium" and that he would probably realise what he had achieved only later.
"I'm also happy that Slovenians and their fans have lifted the race to another level. I enjoyed in the exceptional support. Thanks to everybody who came to support us," was Roglič's message to fans.
Roglič was in the overall lead for the first five stages as the first Slovenian ever to manage that at the Grand Tour races.
By stage eight, he dropped to 12th place, but in the following stage, he climbed back to the 2nd overall.
Roglič kept the second overall place until stage 16, when he dropped to 3rd, the place he kept until the 19th, mountain stage, when he was overtaken by Landa after receiving penalty seconds.
Slovenia's Jan Polanc (Bahrain Merida), who briefly wore the pink jersey as the race leader in stages 12 and 13, finished the race in the 14th spot overall. His compatriot Grega Bole was 110th.