Gaviria (Quick-Step Floors), held off world champion Peter Sagan (BORA-hansgrohe) in a bunch sprint at the end of the 168km stage from Ascoli Piceno to Civitanova Marche to win by half a bike wheel. Jasper Stuyven (Trek-Segafredo) was third.
“It was a complicated and dangerous sprint,” Gaviria said. “It was difficult for a single team to organise a train but we managed to win and we’re happy.
“I knew I had put my front wheel before Peter Sagan on the finishing line but I went to him afterwards to apologise for not giving him turns earlier on when we rode away. I couldn’t because my team-mate Niki Terpstra was at the front.
“I kept my eyes on him (Sagan) and when I noticed he wanted to open his sprint, I decided to move first. I had good legs and enough power to keep a small gap, even if he was coming back really strongly. He is one of the best riders in the peloton and to beat him it’s an honour.”
Quintana (Movistar) remained 50 seconds ahead of Thibaut Pinot (FDJ), and 1 minute, 6 seconds ahead of Australia's Rohan Dennis (BMC).
The final stage is a 10km individual time trial around San Benedetto del Tronto, in which Dennis will be a favourite.
"I feel good going into tomorrow's time trial, and I should have a good ride," he said. "I felt really strong today, especially in the finish.
"I could move up really easily, so I am aiming for the best possible result tomorrow. Obviously, first I want to go for the stage win and then I can look towards hopefully moving up on the GC."
There was some drama on the stage with half the race to go when the main bunch was forced to stop at a rail level crossing.
As they waited for the train to pass, the break’s advantage increased to over five minutes. Race organisers then forced the group to stop for three minutes in order to reinstate the previous time gap.
Data Summary - Fernando Gaviria
Speed: 27.3km/h (As the road sloped upwards, the field significantly reduced its speed and the break increased its advantage)
Power: 247W (Max: 668W)
Heart Rate: 140bpm (Max: 164bpm)
Highlight effort: 345W for three minutes as Gaviria caught up with the peloton. Gaviria stopped for a few seconds and had to chase back to the field.
Stop at a train crossing
The field had stop at a train crossing with about 85km to go. A unexpected break for the peloton. The superior aerobic conditioning of professional riders is shown as Gaviria is able to bring down his heart rate from 125bpm to 68bpm quickly after hours in the saddle.
Last Climb (1.4km – 6.3 per cent - 89 metres)
Time: 2min 43sec
Speed: 30.2km/h (A very high pace on a 6 per cent gradient)
Power: 478W (30sec Peak Power of 551W as the ascent begins)
A very strong performance by Fernando Gaviria as he showed his versatility by staying near the front on a tough last climb. He was still able to deliver his sprint after this hard effort.
Time: 3min 2sec
Speed: 59.2km/h (Incredible average speed on the tricky final circuit in Civitanova Marche)
The Sprint (Last 300 metres)
Time: 14sec (264 meters)
Speed: 67.4km/h (Max: 69.8km/h)
A very fast sprint from an already splintered front group. Gaviria came from his teammate’s wheel with 300 metres to go to open up his winning effort. He put out 1017W for 14 seconds to beat Peter Sagan into second. He peaked at 1277W during the last acceleration that gave him the decisive advantage.