The Slovenian hit the front as the gruelling 220 kilometre hilly route – the longest stage of the Volta – reached its conclusion to take victory ahead of Julian Alaphilippe and Samuel Dumoulin.
Joaquim Rodriguez finished in the lead bunch to retain his four second lead over Alberto Contador in the general classification.
Mezgec’s Giant-Shimano team-mate, Georg Preidler, was one of eight riders that formed the early breakaway, but the group’s advantage withered as it shrank in size and was eventually reeled in by the pursuing pack.
With time bonuses on offer for the top three, Contador put himself in contention for the sprint but was unable to hold on and was forced to settle for sixth.
"I had no idea if I could win today because of that final climb, so that’s why we had a guy in the break [Preidler]", said Mezgec.
"I was the plan B. for today. I didn’t start the stage hoping I could win."
Stage five results
1. Luka Mezgec (Slovenia / Giant) 5:15:59"
2. Julian Alaphilippe (France / Omega Pharma - Quick-Step) ST
3. Samuel Dumoulin (France / AG2R)
4. Paul Martens (Germany / Belkin)
5. Michel Kreder (Netherlands / Wanty)
6. Alberto Contador (Spain / Tinkoff - Saxo)
7. Adam Yates (Britain / Orica)
8. Kevin Reza (France / Europcar)
9. Tosh Van der Sande (Belgium / Lotto)
10. Davide Vigano (Italy / Caja Rural)
1. Joaquim Rodriguez (Spain / Katusha) 23:03:34"
2. Alberto Contador (Spain / Tinkoff - Saxo) +4"
3. Tejay van Garderen (U.S. / BMC Racing) +7"
4. Romain Bardet (France / AG2R) +10"
5. Nairo Quintana (Colombia / Movistar)
6. Chris Froome (Britain / Team Sky) +17"
7. Andrew Talansky (U.S. / Garmin) +18"
8. Domenico Pozzovivo (Italy / AG2R) +26"
9. Warren Barguil (France / Giant) +42"
10. Robert Kiserlovski (Croatia / Trek) +48"
- Sports & Recreation
- Alberto Contador
- Samuel Dumoulin
- Joaquim Rodriguez