SAN FRANCISCO -- Bruce Bochy envisioned a disappointing flight to St. Louis that might have been if San Francisco's mistake-filled funk had extended into another day against the Oakland Athletics.
Pablo Sandoval hit a go-ahead two-run single in the sixth, Barry Zito delivered another timely victory to end a six-start winless stretch, and the Giants beat the Oakland Athletics 5-2 on Thursday to avoid a season sweep in the Bay Bridge Series.
"If this game got away from us, it would have been a long flight to St. Louis, believe me," Bochy said. "I thought today was really critical. There's some pride involved. The last thing you want to do is get swept here in this Bay Series."
A day after San Francisco made three errors and two other defensive miscues, the Giants finally got to A.J. Griffin (5-4) to snap the A's six-game winning streak with their lone win in the four-game interleague rivalry between last year's West division champions.
Brandon Belt doubled in two runs in San Francisco's four-run sixth.
Zito (4-3) won against his former club for his first victory since beating San Diego at home April 21. The Giants improved to 7-0 in his home outings and have won 13 straight regular-season games started by Zito at AT&T Park.
"He was just being Zito out there," Belt said, "We needed it."
San Francisco hasn't lost a home start by Zito since last Aug. 2 against the New York Mets. The Giants have won 13 straight starts by the lefty when including Game 1 of the World Series last fall against the Tigers.
Oakland (31-24) missed a chance to move a season-best nine games over .500 and lost for only the second time in 13 games. The A's have dropped 11 of their past 14 in the Giants' waterfront ballpark, which drew a sellout crowd of 41,250 for the afternoon finale.
"I think our team showed a lot of fire and we were competitive," A's third baseman Josh Donaldson said. "You go through a season and get tons of opportunities when you don't come through. But at the same time we're playing the game right way and I guarantee you we'll be ready for the White Sox."
The Giants lost the first three games of this Bay Area rivalry to drop the season series for the first time since going 2-4 in 2008 after a sloppy 9-6 loss Wednesday night.
Sandoval's hit in the sixth gave the Giants their first lead in 23 innings.
"We've been waiting on an inning like that," Bochy said.
San Francisco avoided its first season sweep by the A's since the clubs began playing interleague matchups in 1997.
Zito faced trouble in each of his first five innings before finishing his day with a 1-2-3 sixth. He delivered just the third quality start in the past 16 by the Giants' struggling rotation. The 2002 AL Cy Young Award winner for Oakland is 3-4 in seven career starts against his old team.
"I get some juice just because it's a tough team," Zito said. "We've got a lot of talent in the Bay right now. It's good to see. We definitely know what we need to do, we have to go out there and be better on the starting side."
Sergio Romo, San Francisco's fourth reliever, finished for his 14th save in 16 chances.
Zito allowed a leadoff double to Crisp in the first and Jed Lowrie's walk before the two pulled off a double steal, but Zito then retired the next three Giants batters in order to escape unscathed.
He allowed a two-out walk to Griffin -- making his first career plate appearance -- in the second then Crisp's single, and pitching coach Dave Righetti paid the lefty a mound visit.
Cespedes walked leading off the third, but was caught stealing. Donaldson walked, then Nate Freiman grounded into an inning-ending double play.
"Amazing, really," Bochy said. "He was quite the Houdini today. I don't know how he did it."
Zito walked a season-high six batters, struck out five and allowed one run and three hits in six innings. Zito's 117 pitches were his most since also throwing 117 on Aug. 6, 2010, at Atlanta.
Griffin, a younger version of Zito with his similar style and big curveball, gave up four runs and five hits, struck out five and walked one in 5 2/3 innings.
A's manager Bob Melvin spent more than an hour in traffic Thursday morning trying to get across the bay during rush hour -- after doing the same leaving late Wednesday.
"Literally the Bay Bridge Series," he said. "I was on the Bay Bridge an hour last night and an hour this morning. Quick turnaround."
San Francisco CF Angel Pagan will test his injured left hamstring Friday in St. Louis with batting practice and running. He received a cortisone shot Wednesday and has missed five straight games. He could play as soon as Saturday. "Hopefully very soon. I'm going crazy right now," he said. ... Giants 2B Marco Scutaro was out of the lineup with what Bochy calls "the crud" that has been going through the clubhouse. ... RHP Chad Gaudin will start Sunday at St. Louis for the Giants if not needed before, and Bochy believes he can go five or six innings considering he has 75 major league starts and has thrown 70-plus pitches. ... San Francisco RHP Ryan Vogelsong had his cast removed from surgery last week on his broken pitching hand. He is now wearing a splint and began working out again Wednesday.