SAN FRANCISCO — Justin Ruggiano hit a leadoff homer to get Miami started and capped the game with a two-run shot in the ninth inning to lead the Marlins to their 10th win in their last 11 games in San Francisco, 7-2 over the Giants on Sunday.

Nathan Eovaldi (1-0) held the Giants in check into the seventh inning and Marcell Ozuna hit an RBI double and solo homer as the Marlins bested Matt Cain (5-4) and a struggling San Francisco bullpen.

The defending World Series champion Giants dropped three of four at home to the team with the worst record in the National League, scoring just eight runs in the four games.

The Giants went 3-4 on the homestand that started with three games against San Diego, marking their first losing homestand since going 3-7 from July 23-Aug. 2 last summer. San Fracisco had won or split the last 10 homestands.

The Giants did end a 90-inning home run drought when Hunter Pence led off the seventh against Eovaldi with a drive over the left field fence for his 12th of the season to cut Miami's led to 3-2. It was San Francisco's first homer since a leadoff shot by Gregor Blanco on June 14 in Atlanta.

The eight homerless games coincided with an injury to third baseman Pablo Sandoval, who has been out since June 8 with a left foot strain. Sandoval homered the past two days on a rehab assignment with Class A San Jose and is on track to be activated Monday for the series opener in Los Angeles.

"This lineup needs a little shot in the arm right now and his presence certainly will help," manager Bruce Bochy said before the game.

But Sandoval could only watch against Eovaldi and the Marlins.

Eovaldi allowed just two hits in the first five innings — a line drive that went in and out of the glove of sliding right fielder Giancarlo Stanton in the first inning and an infield hit between the pitcher's mound and first base by Blanco in the fourth.

Eovaldi was finally touched for a run in the sixth when pinch-hitter Tony Abreu tripled and scored on a groundout by Marco Scutaro. Eovaldi's day ended when he walked Brandon Belt following Pence's homer in the seventh. He allowed two runs and four hits in six-plus innings.

Ryan Webb preserved the lead when he got pinch-hitter Joaquin Arias to hit into a double play with runners on first and third to end the seventh.

Chad Qualls pitched a scoreless eighth with help when Scutaro made the second out at second base when he tried to advance after Stanton threw to third following a single.

The Marlins broke the game open with a four-run ninth against Jean Machi that featured homers by Ozuna and Ruggiano. It was Ruggiano's second career multihomer game.

Cain pitched fairly well after the leadoff homer by Ruggiano on the second pitch of the game. Cain struck out eight batters and walked none in six innings.

The Marlins scored single runs in the fourth on an RBI double by Ozuna and sixth when first baseman Belt couldn't handle a hot shot by Logan Morrison for a run-scoring error that made it 3-0.

NOTES: The Giants are uncertain whether RHP Chad Gaudin will be able to start Tuesday in Los Angeles after he took a line drive off his pitching elbow in his last start. ... Madison Bumgarner (7-4) will start the series opener against the Dodgers versus Hyun-Jin Ryu (6-3). ... The Marlins are off Monday before beginning a two-game home series Tuesday against Minnesota.