Keith Bechtol, 25, of Palo Alto, posted an unofficial time of 2 hours 23 minutes 28 seconds.
The Stanford University graduate student, who is studying astrophysics, said he's been running for 11 years but only registered for the marathon six weeks ago.
"I wanted to do an event that was sort of right here so I wouldn't feel the pressure of going someplace new," Bechtol said. "It felt more familiar, and being from Palo Alto I'm close to the city but I actually don't visit as much as I should."
He said he wasn't sure what to expect from the race, though.
"I kind of went out with the attitude that I'm just going to settle into a pace that was comfortably hard," he said.
Runners in the marathon are released in waves. Bechtol, who started in the third wave at least three minutes behind the first pack of runners, said he always felt second place finisher Michael Wardian wasn't far behind.
"For me in those last miles, I felt like I really had to push knowing he was close," Bechtol said. "I kind of had this feeling knowing he wasn't going to slow down."
Wardian, 36, of Arlington, Va., also broke the old course record with his time of 2:25:21.
Harm Sengers, a 27-year-old from the Netherlands, finished third with a time of 2:29:23.
Andrew Cook, of Texas, set the previous course record of 2:25:57 in 2007. Cook, who has won the marathon three times, did not race this year because his wife is about to have a baby, marathon spokeswoman Lyz Luke said.
In the women's full marathon, Emily Harsin, 24, of Durham, N.C., took first with a time of 2:51:54. In second place was Brandy Bengoechea, 38, of Nampa, Idaho, at 2:53:26. Morgan Robinson, a 24-year-old from San Francisco, finished third with a time of 3:01:11.
The 26.2-mile marathon course starts and finishes on the Embarcadero. The route passes through Fisherman's Wharf and the Marina, crosses the Golden Gate Bridge, and leads runners through the Presidio and Golden Gate Park, along Haight Street, and through the Mission, Potrero Hill and Mission Bay neighborhoods.
Bechtol, who ran track and cross country at the College of William and Mary in Williamsburg, Va., said he especially enjoyed running the city streets without traffic and seeing the Golden Gate Bridge shrouded in fog. His wife, Ellen, met him at the finish line.
"I was just taking it one step at a time, and I wasn't expecting that this one would go as well as it did," Bechtol said. "I guess I'll have to look at the calendar and see what (upcoming race) looks fun."
Official results for all races will be released next week, Luke said. Unofficial results are available now at www.thesfmarathon.com.