Brett Pill's go-ahead two-run single highlighted the San Francisco Giants' three-run seventh in their 4-2 win over the Los Angeles Dodgers in the second test of a four-game set.
Madison Bumgarner (12-9) fanned six and surrendered two runs on five hits and two walks over six innings for the Giants, who have won four of their last six games.
Sergio Romo picked up the final four outs to notch his 34th save of the year, while Hunter Pence smacked a solo homer in the triumph.
Clayton Kershaw (14-9) struck out six and allowed three runs -- two earned -- on eight hits over seven frames for Los Angeles, which has dropped six of its last nine tilts.
"Clayton just had a rough inning," Dodgers manager Don Mattingly said of his starter. "They have a good ballclub. They got guys on base and they took advantage."
Los Angeles' magic number to clinch its first NL West title since 2009 did dwindle to four games following the Colorado Rockies' 7-5 win over the Arizona Diamondbacks.
Juan Uribe cracked a two-run shot in defeat.
Uribe's blast in the sixth staked the Dodgers to a 2-0 lead before the Giants plated three in the seventh and another in the eighth to surge ahead.
Three straight singles by Pence, Pablo Sandoval and Joaquin Arias pushed across the Giants' first run before Pill's base hit to right brought home Sandoval and Arias for the go-ahead runs.
Pence's two-out blast to center made it 4-2 in the eighth.
Mark Ellis and Jerry Hairston singled to start the ninth to put the tying run at first, but Yasiel Puig struck out, Nick Punto grounded into a force out and Adrian Gonzalez bounced one off Romo's foot, which ricocheted to Arias at third and he threw out Gonzalez to end it.
"It got scary the last couple of innings but our pitchers picked us up," Giants manager Bruce Bochy said. "I'm happy for Bumgarner to get the win."