LOS ANGELES (CBS/AP) — Pablo Sandoval and Hector Sanchez hit RBI singles in the 10th inning, and the San Francisco Giants recovered to beat the Los Angeles Dodgers 7-4 Sunday after closer Sergio Romo gave up a tying homer to Hanley Ramirez.

Brandon Hicks hit a two-run shot off Clayton Kershaw, and Buster Posey had an RBI single for the NL West leaders, who beat the defending division champions for the seventh time in 10 meetings this season.

READ MORE: 3 Teens Accused Of Killing Man, Stealing His Dog & Car In San Francisco On New Year's Eve

The Giants finished their road trip 7-3 and played errorless ball over the last five games.

Romo (3-0) came on in the ninth to try and protect a 4-2 lead for Tim Hudson. The right-hander struck out Yasiel Puig after a one-out double by Dee Gordon, but Ramirez lined his fifth homer to left field on an 0-1 pitch. The blown save was Romo’s first this season in 13 chances.

Angel Pagan drew a leadoff walk in the 10th from Dodgers closer Kenley Jansen (0-2). Hunter Pence singled and both runners advanced on a wild pitch before Posey was intentionally walked. Sandoval and Sanchez delivered clutch hits, then Posey scored on J.P. Howell’s wild pitch.

Jean Machi got three outs for his first major league save.

Sandoval, who began the day batting .173, started in the cleanup spot for the third time and was 3 for 5 with two RBIs. His other six RBIs this season came when he was batting third.

Sandoval’s run-scoring double in the first ended an RBI drought of 20 games and 68 at-bats for the switch-hitting third baseman since April 16 against the Dodgers. It was only the third hit with a runner in scoring position in a span of 27 at-bats for Sandoval, who clapped his hands as he went into second base standing up.

Hudson allowed two runs and eight hits over six innings, including a leadoff homer in the sixth by Puig that extended his career-best hitting streak to 11 games. The right-hander, coming off a complete-game, 2-1 loss at Pittsburgh on Tuesday, went fewer than seven innings for the first time in eight starts this season.

READ MORE: Santa Clara County Courts Reopening To Public As COVID-19 Omicron Surge Declines

Kershaw allowed three runs and seven hits in his third start of 2014 and first at Dodger Stadium. The two-time Cy Young Award winner and three-time defending major league ERA champ struck out nine and walked none in his second outing since coming off the disabled list. He also had nine Ks and no walks last Tuesday at Washington, when he pitched seven scoreless innings in an 8-3 win.

Sandoval led off the seventh with a single and Hicks followed with his seventh homer, a drive to left field on an 0-2 pitch. The Giants have 45 homers through 38 games, their highest total at this stage of a season since 2001 (51).

Hicks also went deep against Josh Beckett on Thursday in the Giants’ series-opening 3-1 win.

Los Angeles grabbed a 2-1 lead in the sixth. Puig drove Hudson’s first pitch of the inning into the Dodgers’ bullpen in left to tie the score 1-all, and flipped his bat after making contact. But unlike Friday night—when Puig did the same thing after homering against Madison Bumgarner before the lefty barked at him on his way to home plate—Hudson just stood on the mound with his back to the third base line and rubbed up another baseball.

Ramirez then legged out a double that got past shortstop Ehire Adrianza—just beating Adrianza’s tag after he got the relay from Pagan in center field and scurried to the bag. Adrian Gonzalez followed with an RBI single that ended a 2-for-33 drought.

Gonzalez tried to score from second on Drew Butera’s single, but Pagan threw him out at the plate.

NOTES: Beginning with Monday night’s game against the Marlins, fans entering Dodger Stadium will be going through metal detectors at selected gates for a limited number of games the rest of the season. The new security measures, which Major League Baseball is implementing in conjunction with the Department of Homeland Security, are expected to be in all big league ballparks by next year. … Sandoval’s double came on the first pitch. He came in 2 for 62 with 29 strikeouts when he had two strikes on him. … Andre Ethier doubled his first two times up. He is 6 for 25 against Hudson, and all the hits have been for extra bases—five doubles and a triple. … The Giants don’t return to Dodger Stadium until Sept. 22.

MORE NEWS: San Francisco Police Preparing to Handle Niner Fan Festivities on Sunday

© Copyright 2014 The Associated Press. All Rights Reserved. This material may not be published, broadcast, rewritten or redistributed.