Cavendish edged Tom Boonen by less than half a bike length in the 115.4-mile road race from Merced to Clovis.
Juan Jose Haedo of Argentina was third.
Seven-time Tour de France winner Lance Armstrong, who began the day in fourth place, also finished in the main field. Armstrong remained 30 seconds behind Leipheimer.
"It was a hard race and it was aggressive racing," said Armstrong, who was informed about halfway through the stage that his bike stolen four days ago in Sacramento was found.
"It wasn't that easy today.
"All and all it was a tough day."
Leipheimer, of Santa Rosa, kept his 24-second advantage over Australian Michael Rogers.
American David Zabriskie remained third overall, trailing by 28 seconds.
The fourth stage included five climbs and advanced into the Sierra Nevada. Race organizers cleared ankle-deep snow in some segments prior to the stage.
Kim Kirchen of Luxembourg, three-time former world titlist
Oscar Freire of Spain and Scott Nydam of Sebastopol, all abandoned with undetermined injuries after crashing during the stage.
Leipheimer, who took the overall lead after a second-place finish in Stage 2, avoided crashing and rode while surrounded by teammates.
"The first 1 ½ hours were blazing," he said. "Even Lance took some monster pulls and brought back four of five guys on his own.
"It's great to have such a strong team."
The nine-day event continues Thursday with the 134.3-mile stage from Visalia to Paso Robles, the longest leg of the event.
Tour of California
A 115.4-mile road race from Merced to Clovis
1. Mark Cavendish, Great Britain, Columbia-Highroad, 4 hours, 42 minutes, 38 seconds.
2. Tom Boonen, Belgium, Quick-Step, same time.
3. Juan Jose Haedo, Argentina, Saxo-Bank, same time.
4. Thor Hushovd, Norway, Cervelo, same time.
5. Tyler Farrar, United States, Garmin-Slipstream, same time.
6. Markus Zberg, Switzerland, BMC, same time.
7. Freddy Rodriguez, United States, Rock Racing, same time.
8. Sebastian Haedo, Argentina, Colavita-Sutter Home, same time.
9. Bernard Sulzberger, Australia, Fly V Australia, same time.
10. Martin Elmiger, Switzerland, AG2R-La Mondiale, same time.
1. Levi Leipheimer, United States, Astana, 18 hours, 33 minutes, 52 seconds
2. Michael Rogers, Australia, Columbia-Highroad, 24 seconds behind.
3. David Zabriskie, United States, Garmin-Slipstream, 28 seconds behind.
4. Lance Armstrong, United States, Astana, 30 seconds behind.
5. Christopher Horner, United States, Astana, 34 seconds behind.