SAN FRANCISCO -- Brian Wilson felt bad. Matt Cain felt good. Winning means you don't have to apologize.
Pinch-hitter John Baker hit a three-run homer in the top of the inning to tie it at 5 as Wilson (1-2) suffered his first blown save since May 2.
"I feel pretty terrible about not being able to hold it for Cainy," Wilson said. "But the bottom line is we won. Giving up a three-run homer in the ninth is not a lot of fun. Regardless of whether it's 100 in a row or whatever, I need to keep doing my job."
Matt Lindstrom (1-2) walked Dave Roberts, gave up a single to Randy Winn, who homered in the game, and intentionally walked Aaron Rowand ahead of Molina.
"I thought I made some good pitches but walking the leadoff guy, it's not good," Lindstrom said. "These guys fight so hard for the win and it unravels in five minutes. It's frustrating all the way around."
Rich Aurilia, Fred Lewis and Emmanuel Burriss drove in runs for the Giants, who won for the fourth time in six games. Pablo Sandoval and Rowand both had two hits.
"Their guy was pitching well," Giants manager Bruce Bochy said. "After the first inning he was going right through us. Then we had a lot of big hits and that put us ahead."
Jeremy Hermida hit a two-run homer with two outs in the fourth to give the Marlins a 2-1 lead. It was the first home run hit off Cain since June 4, a span of 14 starts and 94 innings.
"He doesn't have to apologize to me," Cain said of Wilson. "I know he's not happy with what happened. It doesn't matter if I win six games or 20 games. The important thing is the success of the team. It doesn't matter how you get there."
Cain gave up two runs and five hits in 7 2/3 innings. He walked four and struck out four. He has a 1.88 ERA over his last eight games.
"I was just trying to stay aggressive and get these guys to put the ball in play," Cain said. "I wanted them to swing early in the count."
Wilson gave up a leadoff double to Cody Ross and a two-out single to Alfredo Amezaga ahead of Baker. Wilson, who blew his third save in 36 chances, had converted 24 straight.
"The guy throws 100 miles an hour," Baker said. "I wasn't doing anything special. In fact, it was like going back to youth baseball when I'd go up against a hard thrower and the coach would tell me to swing easy and let the pitcher provide the power."
Marlins starter Scott Olsen was looking at his fifth straight loss until Baker got him off the hook. He allowed four runs and nine hits in six innings, walking two and striking out two.
The Marlins committed three errors, including a catcher's interference call on Paul Lo Duca, who later sported a large bandage on his left hand, that produced an unearned run for San Francisco in the seventh. They had made two errors in their last 10 games.
Winn led off the first with his seventh home run. It was his third leadoff homer of the year and the 16th of his career.
Winn opened the seventh with a single. The Marlins called a pitchout during Ivan Ochoa's at-bat. The Giants apparently called a hit-and-run on the same pitch and Ochoa hit the back of Lo Duca's left hand while swinging at a pitch outside the strike zone. Molina later singled to score Winn.
Marlins shortstop Hanley Ramirez left the game with a right thumb contusion after the fourth inning. Baker was hitting for Lo Duca in the ninth.
The Giants improved to 5-3 at home in their last eight games. They were 3-7 in their previous 10. ... A Marlins starting pitcher allowed more than three runs for the first time in 10 games. ... Cain has allowed one run in the second inning all season. ... Winn is hitting .444 in August, second-best in the NL behind Washington's Rafael Belliard. ... Marlins manager Fredi Gonzalez said Lo Duca did not come out of the game because of the injury.