21 year-old Bernal worked the tactics well with teammate Tao Geoghan Hart on the penultimate climb of Daggett Summit to jump away from previous race leader Tejay van Garderen (BMC).
He then had the strength to keep pushing out his advantage and ended up finishing a minute and 28 seconds ahead of second-placed Adam Yates (Mitchelton-Scott).
'I attacked on the last long climb," said Bernal, "but after that there was ten kilometres of a flat section, so I just tried to push hard. I knew that in the last kilometre that maybe I could win the race.
The team is very, very strong. I'm so proud of the team, the guys, the staff, the effort. This victory is for them as they work so hard for me. Tao Geoghan Hart, the guys in the flat... I'm so proud to be part of this team."
The young rider heads into the final flat stage with over a minute's advantage on van Garderen, almost assured of taking his first overall stage race victory on the World Tour.
As it happened
The early breakaway was only formed after a lot of attacking off the front of the peloton. With a lot of categorised climbs on offer, there was the lure of a potential King of the Mountains jersey as well as the stage win.
Stage 3 winner Tom Skujiņš (Trek-Segafredo) fought out the battle for the polka dot jersey with Evan Huffman (Rally) in a see-sawing affair over the climbs on the course.
With enough points secured over the early climbs, Skujiņš was able to secure the mountains jersey and now just needs to stay upright to win the classification on the final stage.
Back in the peloton, BMC were content to let the breakaway slip up the road and the main bunch just cruised along until Team Sky came to the front to attempt to make the race hard and set up Egan Bernal to attack the yellow jersey.
On the penultimate climb of Daggett Summit, the remnants of the breakaway got swept up as Lachlan Morton (Dimension Data) attacked off the front of the race, going solo with 18 kilometres remaining.
That sparked action in the main bunch, as Team Sky dramatically ramped up the pace, catching Morton and thinning the group down to a select few.
Tao Geoghan Hart (Team Sky) made the first major attack, with van Garderen made to go to the front of the group.
Bernal then attacked over to Geoghan Hart and while van Garderen was able to bridge over, an immediate follow-up attack by Bernal distanced the race leader.
With Bernal rapidly growing the gap, Adam Yates (Mitchelton-Scott) managed to make it back to van Garderen and lent a hand with the pace-making, as he had the opportunity to jump up to a podium position.
Yates then attacked again over the top of Daggett Summit, leaving van Garderen to fall into the third group on the road.
Bernal crested the climb with just over a minute's advantage to the chasing group of Yates, Geoghan Hart and Martinez.
There was a general regrouping on the descent and flat section before the final climb to South Lake Tahoe, with only Bernal left out front, powering his way to a second stage win and the leader's jersey.
Yates attacked on the final climb in an attempt to move himself onto the overall podium, but finished just off the mark despite finishing second on the stage.
Van Garderen hung to keep second on the general classification, while Davide Martinez (Education First EF-Drapac) slots into third overall.
Coverage of the Tour of California continues for the final stage of the Mens and Womens events from 5.00 AM AEST on Sunday 20 May.