Tim Hudson allowed one run in 7 1/3 innings, and Hunter Pence delivered a two-run single as the Giants defeated the Marlins, 5-3, at Marlins Park.
Miami has now dropped six straight and lost the first two coming out of the All-Star break to San Francisco. Hudson improved to 15-4 lifetime against Miami.
In the first half, the Marlins had a stretch of winning 10 straight times with Alvarez on the mound. But the right-hander exited after 2 2/3 innings, giving up two runs, with one earned.
"It's unfortunate, but it happens," Alvarez said in Spanish. "When I put my hand on my leg where I got struck by the ball, I felt a big bump so I figured it was probably my best bet to exit the game now."
The fortunate news for Miami is Alvarez appears to be fine. An X-ray came back negative, and he is not expected to miss his next start. Alvarez was walking fine as he left the ballpark.
"That's a big hit. Thankfully he's OK," Miami catcher Jarrod Saltalamacchia said. "It could have been a lot worse than it was. The bullpen came in and did the best job they could. That's a tough situation to come in on. You're not expecting that that early."
The Marlins fell behind by four runs in the fourth inning, but made things interesting in the ninth inning.
Giancarlo Stanton smashed a homer leading off the inning against Giants reliever Sergio Romo. Marcell Ozuna doubled off Romo with two outs, then moved to third on Santiago Casilla's wild pitch and scored on Saltalamacchia's single.
"He's going to do some damage," Giants manager Bruce Bochy said of Stanton. "You just hope you limit the damage, which we've been fortunate to do. When he hits them, they're no-doubters. That's quite a talent."
Stanton has homered in each of the first two games in the series, boosting his National League-leading total to 23.
"Hopefully that gets him going," Miami manager Mike Redmond said. "We're definitely going to need him. He's the guy, the catalyst to our offense. It was good to see him have a couple big at-bats, a couple home runs. You knew we weren't going to give up."
The injury to Alvarez forced Miami to go to its bullpen before the sixth inning for the second straight night. In Friday's 9-1 loss, Nathan Eovaldi worked four-plus innings.
"You get [6 2/3] innings out of two starters the first two games out of the All-Star break," Redmond said. "You talk about trying to get that bullpen a break and here we are."
With two outs in the third inning, Joe Panik slapped a hard grounder up the middle that struck Alvarez's left leg just above the ankle. Hobbled, Alvarez did make the play to get Panik out, but he immediately was replaced by Sam Dyson, who worked 3 1/3 innings, giving up three runs.
Christian Yelich extended his hitting streak to 12 games with a single to lead off the first inning.
The Marlins were able to capitalize on that hit, because Yelich scored from third on Casey McGehee's two-out RBI single to center.
Miami's lead didn't last long as the Giants scored twice in the second inning, with one run unearned.
Pablo Sandoval doubled to open the inning, and he scored on Brandon Belt's one-out double. Belt put San Francisco ahead with two outs when he scored on Saltalamacchia's passed ball coupled with a throwing error.
Belt left the game an inning later due to dizziness.
The Giants padded their lead to 5-1 in the fourth inning, scoring three times with two outs. Dyson put himself in a bind when he walked Hudson with the bases loaded after Gregor Blanco was intentionally walked. Pence laced a two-run single to right.
The Marlins fell to a season-worst eight games under .500 (44-52).
"You've just got to grind through it," Saltalamacchia said. "Fortunately for us, we've got 21 games against our own division. That's big for us. Right now, it's just getting back in the groove of things."