LOS ANGELES (AP) -- Clayton Kershaw and Madison Bumgarner dueled through five scoreless innings before the Dodgers gave their ace a 2-0 lead.
It didn't hold up after Kershaw got tagged for three runs in the seventh, and the San Francisco Giants went on to a 4-2 victory Friday night.
The Dodgers had a two-out rally going in the ninth, with runners on first and third.
But pinch-hitter Adrian Gonzalez's hard grounder hit off Sergio Romo's right foot and bounced to third baseman Joaquin Arias, who threw to first for the final out.
With second-place Arizona's 7-5 loss to Colorado, the Dodgers' magic number was reduced to four for clinching their first NL West title since 2009.
"It should have been three," Kershaw said. "Hopefully we can close it out pretty soon."
Kershaw gave up three runs -- two earned -- and eight hits in seven innings. The lefty who leads the majors in ERA struck out six and walked none. He had won three straight home starts against the Giants.
"The breaks didn't go our way. It was my fault," he said. "They came right back and battled me all night and got some big hits when they needed to."
Kershaw has hit a rough patch lately. After giving up a season-high five earned runs and career-worst 11 hits in five innings of a 10-8 road win over Colorado on Sept. 2, he served up two solo homers to Jay Bruce over seven innings in Sunday's 3-2 loss at Cincinnati.
Hunter Pence homered and scored twice and the Giants got to Kershaw (14-9) with four consecutive singles to start the seventh.
"He just had a rough inning more than anything else," Dodgers manager Don Mattingly said. "Kersh has been able to shut these guys down a lot, but this is a club that no matter where they are in the standings, this is a championship club over there that we're playing. Those guys have won two of the last three (World Series), and they're not just going to fold up shop."
Bumgarner (12-9) allowed two runs and five hits in six innings, extending his streak of allowing three earned runs or fewer in each of his past 18 starts. The left-hander struck out six and walked two.
Romo got the final four outs to earn his 34th save in 38 chances. He gave up consecutive singles to start the ninth, putting the tying runs on with no outs.
Yasiel Puig struck out swinging and Nick Punto hit into a fielder's choice groundout before pinch-hitter Gonzalez's ground out.
Pence's 22nd homer with two outs in the eighth off Chris Withrow extended the Giants' lead to 4-2.
Pence got a leadoff hit in the seventh and Pablo Sandoval followed with a single. Arias singled, scoring Pence, and Arias took second on a fielding error by Scott Van Slyke.
Brett Pill followed with a single to right, scoring Sandoval and Arias to give the Giants a 3-2 lead.
The Dodgers had the tying run on third in the seventh, but Gonzalez struck out swinging to end the inning.
Juan Uribe sent a 1-0 pitch over the left field wall to give the Dodgers a 2-0 lead in the sixth, scoring Michael Young, who singled.
Notes: Dodgers SS Hanley Ramirez sat out a day after leaving in the seventh inning with mild tightness in his left hamstring. The team said an MRI on Friday showed that Ramirez has an irritated nerve in his back rather than a hamstring issue. He received a cortisone injection and is expected to be available to play next week. Ramirez, the team's best hitter with a .342 average, has had two stints on the DL this season. ... Mattingly said that when LHP Chris Capuano returns from a strained groin, he will initially work out of the bullpen. ... Dodgers OF Andre Ethier left the game in the eighth after tweaking his ankle.