It was a rare long ball yielded by Cosart, who had allowed 14 homers in 270 2/3 innings over 45 starts. But McGehee, with the Marlins in 2014, blasted a 3-1 fastball that ran inside and swung momentum in San Francisco's favor.
"If someone homers off me, it's pretty much right down the middle," Cosart said.
That was the case on the missed location of his 3-1 offering.
Given a four-run early lead, Tim Lincecum was able to keep putting up zeros. The Marlins did have a chance in the fifth inning, loading the bases with two outs. Lincecum ended the threat by striking out Giancarlo Stanton on three pitches.
"The second inning was the story of the game," Cosart said. "It pretty much put us in a hole. Me and Tim both threw a lot of pitches. It was a battle to see who would make the first mistake. I ended up doing that. He got out of a big jam, and I wasn't able to. That was pretty much the story of the game."
Cosart worked a season-short four innings, giving up four runs on six hits. He threw 39 of his 83 pitches in the second inning.
"My second inning was just a battle," Cosart said. "I had McGehee up, who hits into a lot of double plays. The situation was there. I threw the ball right down the middle. Like I said last game, that doesn't work against anybody, if they're hitting .100 or .500, you can't throw balls down the middle, and I did."
McGehee had one homer and three RBIs before his shot to center cleared the wall.
"Even a sac fly there would have limited it to one, and I had the pitcher coming up next there," Cosart said. "That's more ideal than what happened."
Cosart has now had two straight rough outings. In a loss to the Phillies on Sunday, he gave up three runs in five innings.
"He's still a young guy trying to get consistent," manager Mike Redmond said. "That's the key for him. The secondary pitches are important. He's got to be able to get a feel and throw those pitches behind in the count for strikes. Right now he's having a tough time doing that."