Updated

Even having ace Clayton Kershaw pitching in his favorite ballpark wasn't enough to get the Los Angeles Dodgers out of their recent funk.

Kershaw allowed his first earned runs in San Francisco in nearly two years and the Dodgers were shut out for the second straight night by the rival San Francisco Giants, losing 2-0 on Tuesday.

Kershaw (5-4) allowed a solo homer to Melky Cabrera and an RBI single to Pablo Sandoval in the fourth inning to snap a streak of 35 2-3 consecutive innings in San Francisco without allowing an earned run. That was more than enough for Ryan Vogelsong (7-3), who followed up Barry Zito's seven innings in an 8-0 San Francisco win in the series opener Monday with his own gem.

"Tonight I blinked first and it cost us," Kershaw said. "I think we are frustrated but we have to take that anger and aggression to the field and keep coming every day. It doesn't matter who we're playing if we're not winning games. We just have to start playing better baseball."

Kershaw (5-4) allowed two runs and eight hits in six innings but got no support from the Dodgers' struggling hitters who sorely miss injured slugger Matt Kemp.

This marked the first time the Dodgers had been blanked in consecutive games in San Francisco since 1987 and for the second time ever.

"It's hard to do, especially against a good club," Giants manager Bruce Bochy said. "Our pitching has been right on in this series. Vogey was tough today, good stuff, good command."

Los Angeles has dropped seven of eight on a nine-game California trip that concludes Wednesday against the Giants, getting outscored 35-13 in the process.

"You get shutout a couple days and there's frustration," Dodgers manager Don Mattingly said. "That's natural. It's my job to make sure we keep going."

Kershaw had won six straight decisions against the Giants, allowing earned runs in just two of those seven outings before falling 2-1 at home on May 8 when Brett Pill hit a two-run homer and Vogelsong shut down the Dodgers for 7 1-3 innings.

San Francisco used a similar formula to get to the reigning NL Cy Young winner in this game with Cabrera providing the power and Vogelsong once again delivering a stellar start.

"I feel like I have something to prove every game," Vogelsong said. "Just because I came out on the right side in two games with him that doesn't change. But it's definitely a step in the right direction."

As stingy as Kershaw has been in his career in San Francisco, Vogelsong has been almost as tough. He allowed seven hits and lowered his home ERA to 1.85 in his two seasons with the Giants, second to only to the Angels' Jered Weaver (1.55) in that span.

Jeremy Affeldt pitched a perfect eighth and Santiago Casilla finished for his 21st save in 23 chances.

"We figured this would be a low-scoring game," Bochy said. "We found a way to get a couple of runs against a pitcher who has been hard on us. That's the only way we beat him a couple of times. Score a couple of runs and get a well-pitched game."

Kershaw had struck out four in setting down the Giants for the first three innings. That all started to change on the second pitch of the fourth inning when Cabrera sent a drive that just cleared the wall in left-center for the first homer Kershaw had allowed in seven appearances in San Francisco.

The Giants didn't stop there, getting three more hits in the inning with Sandoval adding an RBI single before Kershaw escaped a bases-loaded jam by striking out Vogelsong and Gregor Blanco to end the inning.

"My fastball command was off," Kershaw said. "I was behind in a lot of counts and they are swinging the bats real well right now."

Kershaw pitched out of trouble again in the fifth, surviving a line drive off his leg by Buster Posey, but it turned out not to matter the way Vogelsong handled the Dodgers hitters.

NOTES: Dave Dravecky and Mike LaCoss shut out the Dodgers on consecutive days in San Francisco in 1987, with LaCoss going 10 innings for his 1-0 win on Aug. 16. ... The Giants had consecutive shutouts against the Dodgers in Los Angeles in April 2002. ... RHP Tim Lincecum (2-8) looks to snap a 10-start winless streak when he takes the mound for San Francisco in the series finale Wednesday against RHP Chad Billingsley (4-6).