Hand, now 2-12 in his career as a starter, won for the first time as a starter since July 7, 2011, against the Astros.
Working with veteran catcher Jeff Mathis, Hand mixed up his pitches and scattered six hits while striking out four.
"We needed seven and he gave it to us," Miami manager Mike Redmond said. "He looked great. I thought he and Matty did a tremendous job keeping these guys off balance. He had command of all his pitches."
McGehee snapped a string of 58 straight games without a home run. And the Marlins ended their six-game losing streak, as they salvaged the series finale.
Batting .322 with 56 RBIs, McGehee has been highly productive batting behind Giancarlo Stanton. The one knock he's received is a lack of home runs. Even the 31-year-old is mildly surprised he doesn't have more, but he insists he isn't going to mess with what has been working.
"It's a little weird," McGehee said. "I would have thought I'd have run into a few more. But at the same time, it doesn't mean too much. I feel like maybe I could have a few more if I was going up there with that being my approach. But I don't think I would have had whatever success I've had if I had that as my approach. Just hitting one, I'm not going to go up there trying to make up for lost time or anything like that. Whatever it ends up being, whether it's two or 30, I don't care. Whenever they show up, they show up."
Steve Cishek worked a perfect ninth inning for his 21st save in 24 chances. It was his first save chance since he was unable to protect a two-run lead in the 10th inning in a 4-3 loss at Arizona on July 9.
"It took a little longer to get him back out there in a save situation than we anticipated," Redmond said. "But he looked good today. His command was great. His misses were down in the zone. It was a very efficient ninth inning."
The Marlins didn't manage much off Tim Lincecum, who gave up five hits over seven innings and struck out seven.
But in the seventh inning, Miami claimed the lead when Adeiny Hechavarria scored on a wild pitch that got away from catcher Hector Sanchez with pinch-hitter Reed Johnson at the plate. Hechavarria doubled to open the inning, and he moved to third on Mathis' sacrifice bunt.
"He's got a lot of movement on the pitches," Giants manager Bruce Bochy said. "He's not easy to catch. Sanchy's done a good job, but that one just kicked away enough to where he could score."
In the first two games of the series, Miami starters combined to throw 6 2/3 innings, increasing the importance of getting a quality start. Hand delivered.
The left-hander matched a career high going seven innings. The only other time Hand went seven was in his win over the Astros in 2011.
"I feel like all my outings have been pretty good since I've been back," Hand said. "Just build on this one. Get the win and try to get out there in five days and get the win."
McGehee had an All-Star-worthy first half, which is a reason he was a Final Vote candidate to make the Midsummer Classic. But the lack of delivering the long ball has become a topic of conversation, and it was noted in All-Star talks.
But in the first inning, with Stanton on second and two outs, McGehee blasted a two-run shot to left-center, snapping a span of 231 consecutive homerless at-bats. His only blast of the first half came in the first inning May 10 at San Diego.
Even without hitting a home run over a 58-game stretch, McGehee did bat .328 with 29 RBIs during his homer drought.
"That was a big hit," Redmond said. "We needed it. This guy's been consistent all year. I know everybody talks about the power, but that was a great swing."
The Giants tied it in the third inning on Buster Posey's two-run double to left. Hand escaped further damage by striking out Pablo Sandoval and Michael Morse.
After the third, Hand allowed just a single and a walk, as he finished up retiring the final 11 of 13 he faced.
"It was a big win," Hand said. "The bullpen got used a lot the past two days, so I was just trying to go out there and get deep in the game and help the bullpen a little bit."