Victory for the Colombian made it two stage wins in his opening event for UAE Team Emirates and underlines his pedigree going into bigger events in the season.
WATCH - Gaviria wins dramatic sprint finish over Sagan
Tour de Slovaquie
Einhorn soars past Sagan to win Stage 4 at Tour of Slovakia
A largely flat stage was always likely to reel in the early breakaway, and so it proved, with a packed peloton lining up for the sprint finish during a long, largely straight run-in.
Gaviria looked like he'd kicked slightly too early, with Sagan getting a great position on the Colombian's wheel, but the 24-year-old held off the multiple time world-champion to edge a photo finish.
Julian Alaphilippe retains his overall lead after victories in the second and third stages.
Stage 3 Report
Julian Alaphilippe won his second stage in two days to build his lead in the Vuelta a San Juan.
The Deceuninck-QuickStep rider set the fastest time around a short ITT course to continue his team's remarkable start to the season.
And there was more good news for Deceuninck as Alaphilippe's young team-mate Remco Evenepoel secured his first ever podium position since turning professional.
Stage 2 Report
Julian Alaphilippe launched a solo attack on the final climb to win Stage 2 of the Vuelta a San Juan.
The Frenchman attacked on the short, sharp closing climb and held off the closing peloton to take the stage win and build on Deceuninck-QuickStep's strong start to the season.
Alaphilippe finished ahead of Simone Consonni and Peter Sagan, but had time to look over his shoulder and celebrate across the line after an attack that hinted he's ready to repeat his fine form from a 2018 season that saw him claim the mountains classification at the Tour de France.
The result means that Alaphilippe trails Fernando Gaviria by just three seconds going into the Stage 3 time trial.
A strong field has entered the Vuelta a San Juan as the 2019 cycling season limbers into action, with Alaphilippe's Deceuninck-QuickStep team-mate Evenepoel Remco among a star-studded field. The youngster came in at 15th on the day, still well-placed in General Classification.
Stage 1 Report
Fernando Gaviria came in late to win a chaotic sprint finish and take the opening stage of the Vuelta a San Juan.
In the final metres of the race a number of teams were leaving it late with Bora in particular holding off despite having both Peter Sagan and Sam Bennett in position.
Eventually Sagan attacked by Bennett couldn’t follow, as it seemed the idea was for the former to lead out for the Irishman given Sagan arrived a day later than the rest of the team.
Sagan did his job but Bennett was nowhere to be seen in a fairly messy ending to the race for Bora, finishing third behind the winner and Matteo Malucelli in second.
While that was going out UAE Team Emirates had put Gaviria in position further across the wide road and the Colombian powered past the pack to secure victory, his first for his new team.
The gap between the breakaway and the rest of the pack fluctuated between 15 and 40 seconds in the final 20km but they were pulled in before the final few kilometres.
The final stretch was both straight and flat, perfect for the sprinters who were set up well by their teams and it was Gaviria who took advantage.
The 2013 winner Daniel Zamora took the maximum points on both of the climbs to take six points and the lead in the King of the Mountains classification. He will wear that jersey going into Stage 2 on Monday.
Starting later due to the intense heat at this time of the year the race didn’t finish until close to 20:00 local time.
Tour de Slovaquie
Halvorsen wins Stage 3 photo finish in Slovakia
Tour de Slovaquie
Steimle wins Stage 2 after Bol crash causes chaotic finish