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.
Competing for Jumbo-Visma, he claimed his second Tour de Romandie title only a week ago, and is viewed as one of the favourites for the three-week Giro d'Italia title.
This was Roglič's second stage win at the legendary race across Italy, which kicked off in Bologna. His first stage win at Giro d'Italia came in 2016.
Britain's Chris Froome has completed a sensational comeback to win the Giro d'Italia for a rare Grand Tour treble which could be in danger if he is sanctioned by anti-doping authorities.
Israel enters uncharted territory on May 4 when it begins hosting the three opening stages of the Giro d'Italia, the biggest international sporting event to be held in the country.
Chris Froome heads into the Giro d'Italia insisting he is focusing on his attempt to make history by holding all three titles from cycling's Grand Tours at the same time.
Vincenzo Nibali fought back tears as he stood on the Tour de France winner's podium and described the moment as better than he ever expected.
Nibali completed his victory at the 2014 Tour by finishing safely in the pack on Sunday's 21st and final stage from Evry to Paris, won by German Marcel Kittel.