Having won Friday’s mountain stage by a handsome margin, Bernal only had to finish in the main group on the flat final stage to Sacramento, and he duly rolled in safely as compatriot Gaviria took his third stage victory of the race.
The early stages saw the usual doomed breakaway formed on this final pan-flat stage, with Neilson Powless (LottoNL-Jumbo), Adam De Vos (Rally Cycling), Mikkel Bjerg (Hagens Berman Axeon), and Jonny Clarke (UnitedHealthcare) going up the road and quickly established a lead of around two minutes.
The four breakaway riders’ lead continuously hovered around the two minute mark for much of the day with the teams’ of the sprinters – Katusha-Alpecin, Mitchelton-Scott, and Quick-Step Floors – keeping the gap under control.
Team Sky also lent a few riders to help with the chase, and by the time the race returned to the centre of Sacramento with 13km to go the gap was coming down rapidly.
Powless put in the biggest effort to stay away, but it was all in vain as Katusha-Alpecin did the final bit of chasing in the last two kilometres to catch the young American and leave Nils Politt to lead Rick Zabel and Marcel Kittel under the flamme rouge.
However Katusha seemed to have hit the front to early, and Zabel was unable to place Kittel to jump into the wheels of the Quick-Step train which came bursting past with 600m to go.
Gaviria was the final man in that train and was the first to open his sprint with 200m to go with Caleb Ewan (Mitchelton-Scott) coming up fast on the left-hand side of the road.
It looked as if the stage win would be contested by those two men until Max Walschied (Team Sunweb) came from nowhere to intersect the two of them and throw his bike towards the line.
The German rider thought he had won it as he crossed the line, but the photo finish showed that Gaviria had clung on to take his third stage win of the race by the narrowest of margins.
Meanwhile Bernal finished in 33rd place to confirm his overall victory by 1-25 ahead of Tejay van Garderen (BMC Racing) and 2-14 ahead of Daniel Martinez (EF Education First-Drapac).
Tour of California 2018, stage seven: Sacramento to Sacramento. 143km
1. Fernando Gaviria (Col) Quick-Step Floors, in 3-07-39
2. Max Walscheid (Ger) Team Sunweb
3. Caleb Ewan (Aus) Mitchelton-Scott
4. Peter Sagan (Svk) Bora-Hansgrohe
5. Miguel Bryon (USA) Holowesko-Citadel
6. Alexander Kristoff (Nor) Katusha-Alpecin
7. Michael Rice (Aus) Hagens Berman Axeon
8. Ty Magner (USA) Rally Cycling
9. Dan McLay (GBr) EF Education First-Drapac
10. Kiel Reijnan (USA) Trek-Segafredo, all at same time
Final general classification
1. Egan Bernal (Col) Team Sky, 25-34-19
2. Tejay van Garderen (USA) BMC Racing, at 1-25
3. Daniel Martinez (Col) EF Education First-Drapac, at 2-14
4. Adam Yates (GBr) Mitchelton-Scott, at 2-16
5. Tao Geoghegan Hart (GBr) Team Sky, at 2-28
6. Rafal Majka (Pol) Bora-Hansgrohe, at 3-01
7. Brandon McNulty (USA) Rally Cycling, at 3-28
8. Laurens De Plus (Bel) Quick-Step Floors, at 3-50
9. Kristijan Durasek (Cro) UAE Team Emirates, at 3-59
10. Mathias Frank (Sui) AG2R La Mondiale, at 4-01