Giant-Shimano's Mezgec surged past Giacomo Nizzolo (Trek Factory Racing), Tyler Farrar (Giant-Shimano) and Nacer Bouhanni (FDJ) in the closing straight to take his first stage victory on a Grand Tour.
But all eyes were on the pink jersey of Nairo Quintana, who leisurely crossed the line with his arms aloft to secure the overall crown over fellow Colombian Rigoberto Uran (Omega Pharma-Quick Step).
Quintana took victory in his first ever Giro d'Italia by 2:58 over Uran with Italian youngster Fabio Aru completing the podium, 4:04 down. Frenchman Pierre Rolland (Europcar) and Italian Domenico Pozzovivo (Ag2R-La Mondiale) completed the top five.
"It's difficult to explain how I feel," said Quintana as a downpour erupted just moments after the riders completed the final 172km stage from Gemona.
"There's so much happiness inside me - it's one of the happiest days of my life. I must give thanks to all my friends and family and team-mates. It's a dream come true."
Quintana had to overcome illness and a heavy crash in the opening week to become his nation's first overall winner in the second biggest stage race of the year.
Controversy marred his stage 16 victory at Val Martello following the neutralisation fiasco on the descent of the snow-covered Stelvio climb, where Quintana allegedly flouted race orders and broke clear with a handful of riders.
But Quintana's victory three days later in the Monte Grappa mountain time trial underlined his credentials as the best climber and strongest rider in the race - and his overall victory in Trieste was thoroughly deserved.
Uran's second place was his successive runner-up spot on the Giro after finishing behind Italy's Vincenzo Nibali while riding for Team Sky in 2013. Uran's victory in the Barolo individual time trial was the first of four for Colombia, with Quintana's two wins sandwiching a superb solo scalp for Julian Arredondo (Trek) who won the blue king of the mountains jersey.
Sunday's final stage was decided by a bunch sprint following eight 7.2km laps of the Adriatic port of Trieste. Mezgec and Bouhanni barged into one another with just 200 metres remaining before the Slovenian propelled himself off the wheel of the Frenchman and surged on the outside of the road to take a memorable win so close to his homeland.
"I was a little under pressure because there were so many Slovenians here today," said Mezgec, who was promoted to Giant-Shimano's main sprinter following the early withdrawal of double stage winner, Marcel Kittel of Germany.
"It could not have been better," Mezgec continued. "It was tough with the climb near the finish but my team had me well positioned and I was very fast in the sprint."
Despite only taking fourth place in the race finale, triple stage winner Bouhanni took consolation in securing the red points jersey.
The final jersey of the race - the white jersey for best young rider - was fittingly won by the rider who also topped the podium in the maglia rosa. Having finished runner-up in his debut Tour de France last July and now winning his maiden Giro, Nairo Quintana is a name world sport will have to get used to for the next decade.
TWO TWO-MEN BREAKS: Maarten Tjallingii (Belkin) and Svein Tuft (Orica-GreenEdge) attacked after 18km on the only categorised climb of the day to bring some delightful symmetry to the 97th edition of the race: Tuft wore the race's first pink jersey after GreenEdge's win in the opening team time trial in Belfast, while Tjallingii - who took the points going over the summit - was the first blue jersey of the race after cresting various summits back in Ireland on the opening weekend of the race.
The break was short-lived but Tuft still felt restless, the Canadian veteran attacking alongside Lars Bak (Lotto Belisol) during the city circuits with 45km remaining. The leading duo built up a maximum lead of 45 seconds before the gap was steadily closed by the peloton.
Stefano Pirazzi (Bardiani), Carlos Quintero (Colombia) and Valerio Agnoli (Astana) attacked on the climb on the third-to-last lap with 18km remaining, catching Tuft and Bak on the descent to create a five-man escape pod. But the quintet was reeled in with 10km remaining to ensure the spectators of Trieste were treated to the grand bunch finale they had been expecting.
BIG WINNERS OF THE DAY: Nairo Quintana resisted the temptation of riding on his custom-made pink Canyon bike until the final stage - and he good reason to celebrate on Sunday after becoming the youngest winner of the Giro since Damiano Cunego a decade previously. Special mention must also go to Luka Mezgec, who have the people of neighbouring Slovenia something to celebrate with an emphatic sprint win in Trieste.
BIG LOSER OF THE DAY: Poor Giacomo Nizzolo - finally the Italian sprinter from Trek managed to get the better of Nacer Bouhanni, but he still finished second for the fourth time in the race.
KEY MOMENT: The banging of shoulders between Bouhanni and Mezgec could have floored both riders but Mezgec somehow kept his balance, kept his cool and then saved his fastest finish for the best possible occasion.
TALKING POINT: With Alejandro Valverde given the nod to lead Movistar during the Tour, should Nairo Quintana refuse to ride as a domestique and instead focus on a tilt at the Vuelta? Win that then surely the Colombian will be the rider of the season - regardless of whatever happens in France this July.
COMING UP: The Criterium du Dauphine, which starts on 8th June, and then the Tour de France, which starts in Yorkshire on 5th July.
- Sports & Recreation
- Nairo Quintana
- Rigoberto Uran
- Nacer Bouhanni