Ackermann (BORA-hansgrohe) finished ahead of Michael Morkov (Quick-Step Floors) and Roberto Ferrari (UAE Team Emirates).
“The guys worked hard to support me the whole day, and in the end, Rudi Selig brought me into the perfect position in the last 200m," Ackermann said.
"I am very thankful for all the hard work of my teammates. It was a real goal of ours to win today and we achieved this. The race has not been easy and it was difficult for me to stay within the time limit on the penultimate stage. So it is nice to see that our hard work paid off.”
Roglic (LottNL-Jumbo) took the yellow jersey after the opening stage and reinforced his grip on the race lead by finishing second in Saturday's climb-heavy fourth stage.
Roglic finished eight seconds ahead Egan Bernal (Sky), with Australia's Richie Porte (BMC), the 2017 champion, in third at 35 seconds.
“I’m speechless. Me and the whole team are happy, very happy with this victory”, Roglic said. “The whole team has done an excellent job this week. This victory is also for my teammates. The boys were very strong and it is a pleasure to work with them and to reward their trust in me with victories.
"I knew I was strong and I was also optimistic, but you still have to do it. That is far from easy. Every day was tough and each stage was decisive. As a team, we have done a fantastic job this week. I can’t express enough how incredibly proud I am of this team.”