SAN FRANCISCO — Pinch-hitter Marcell Ozuna's two-run single gave Tom Koehler his first victory in nine career starts, and the Miami Marlins rallied past the San Francisco Giants 2-1 Thursday night.

Ozuna's line drive to right field in the eighth inning off reliever Jeremy Affeldt (1-3) ended Koehler's stretch of futility. After six appearances in the bullpen, Koehler (1-5) had been winless in seven starts this season — and took the loss in his lone start last year — for the worst team in the majors.

Giants starter Chad Gaudin tossed 4 1-3 scoreless innings, but left the game after taking a hard line drive off his right throwing elbow. The team said he had a bruised elbow.

Joaquin Arias' RBI triple put San Francisco up 1-0 in the seventh.

Koehler kept the Giants off the scoreboard otherwise. He didn't allow a hit until Gregor Blanco's one-out single in the sixth. He struck out three, walked three and allowed three hits.

The right-hander's long-sought victory ended the third-longest winless streak to start a career in Marlins history, behind Marc Valdez's nine-start stretch from 1995-96 and Kevin Olsen's 12-start streak from 2001-02, according to STATS.

Chad Qualls pitched a perfect eighth and Steve Cishek tossed a scoreless ninth for his 11th save.

The Marlins, even with their constant roster shuffling and struggles, seem to be right at home San Francisco's chilly waterfront ballpark the past few seasons. They have won eight in a row at AT&T Park since July 28, 2010.

San Francisco seems to be hounded by unfortunate injuries of late.

Gaudin took a line drive from Derek Dietrich off his elbow, fielded the ball and threw him out for the first out of the fifth inning. Gaudin grimaced as he paced around the mound, then he took a couple practice pitches before coming out.

Gaudin gave up two hits and two walks while striking out one. He was making just his fourth start of the season since entering the rotation for the injured Ryan Vogelsong.

Giants catcher Buster Posey had allowed 21 straight stolen bases until he threw out Adeiny Hechavarria going for second in the third inning. He also nabbed Justin Ruggiano trying to take third base in the fifth.

Koehler walked the leadoff batter in the fourth and fifth innings but never allowed the runner to advance. He got the heart of San Francisco's order — Posey, Hunter Pence and Brandon Belt — on consecutive fly outs in the fifth, and forced Juan Perez to ground into a double play to end the fifth.

The only mark on Koehler came when Belt hit a two-out double in the seventh, sliding in safely when right fielder Giancarlo Stanton's throw sailed wide. Arias followed with an RBI triple in the right-center field gap to extend his hitting streak to 11 games.

Sandy Rosario was taken out after 2 1-3 innings when he walked Ruggiano leading off the eighth. Ozuna later lined a two-out, two-run single to right off Affeldt to give the Marlins the lead.

NOTES: Giants 3B Pablo Sandoval, on the disabled list since June 9 with a strained left foot, will join Class-A San Jose on a rehab assignment Friday — a day earlier than originally expected. He will likely join the Giants in Los Angeles on Monday. ... The Giants announced that Joseph Zito, the father of pitcher Barry Zito, died Wednesday in Van Nuys, Calif., at age 84. The cause of death was not disclosed. Zito, who said in a statement his father's death "has presented me with a difficulty I could not predict," was the first pitcher on the field for batting practice Thursday. He will still make his next start Saturday. ... Ozuna, mired in a 1-for-20 slump, wasn't in the starting lineup off for the first time since being called up from Double-A Jacksonville on April 30. ... Giants SS Brandon Crawford missed his second straight game with two swollen fingers on his right hand. Crawford said his fingers were still slightly swollen but felt "significantly better" than the day before. He's hoping to be back in the lineup Friday. ... The Marlins send Ricky Nolasco (4-7, 3.61 ERA) to the mound Friday and the Giants counter with Tim Lincecum (4-7, 4.57 ERA).