Cain held the Pirates to one run over seven innings to outpitch All-Star replacement Zach Duke, and the Giants, saddened by the death of their part owner earlier in the day, ended an offensive slump by beating Pittsburgh 4-3 on Sunday.
The Giants were limited to two extra-base hits and one unearned run and didn't have an RBI in the first 28 innings of the three-game series before consecutive doubles by Randy Winn, Pablo Sandoval, Bengie Molina and Nate Schierholtz to start the sixth produced three runs. John Bowker added a sacrifice fly to make it 4-1 as the Giants scored the first earned runs off the Pirates' pitching staff in 35 innings.
"Everyone was hitting the ball hard and it felt good to get a little bit of momentum going," said Schierholtz, whose double scored two runs. "It seems like hitting is contagious in those situations and, lately, it seems like it's been a lot of 1-2-3 innings. That inning, everyone kept carrying it on."
The victory came only a few hours after the Giants learned part owner Sue Burns died early Sunday night of complications from cancer. She was diagnosed with the disease July 10 and missed Jonathan Sanchez's no-hitter against the Padres that night -- a rare absence from the ballpark.
The Giants held a pregame team prayer Sunday for Burns, described by manager Bruce Bochy as a "beautiful lady" who watched nearly every game from a box seat near the dugout and always had a smile for players she loved and respected.
"It's unbelievable to think she's gone, really," Cain said. "I don't think we'll realize that until we get back home and we don't see her."
The Giants avoided being swept in Pittsburgh for the second season in a row and stopped a three-game losing streak. The Pirates, who had won 10 of 13 against the Giants, lost their eighth in their last 11 overall despite beating the Giants 2-1 in 14 innings Friday and 2-0 on Saturday.
The Pirates did little against Cain (11-3), who gave up Brandon Moss' solo homer in the second but no further scoring. Cain gave up five hits, struck out eight, walked two and lowered his ERA to 2.32.
Cain pitched for the first time since mound opponent Tim Stauffer of San Diego hit a line drive off his right arm July 11, forcing Cain to be lifted after 1 2/3 innings and putting him out of the All-Star game with a bruised elbow. Cain was replaced on the NL squad by Duke (8-9).
"You could tell by the way he was throwing the ball, he was showing no effects from the shot off the elbow," Bochy said.
A bullpen session Thursday convinced Cain the elbow wouldn't be a problem.
"It took me a little bit to get used to it, the first couple of hitters were a little bit funky, but after that it felt pretty normal and I was able to get back in that rhythm," Cain said.
Duke lost his fourth in a row by giving up seven hits and four runs -- all in the sixth -- over seven innings. The Pirates have scored only seven runs while Duke was on the mound during his losing streak, and one pivotal inning cost him another loss.
"The Giants attack first pitches very well, and you have to make quality pitches from the first pitch of the at-bat," Duke said. "I left some pitches up on the first pitch and they hit them hard."
Affeldt avoided further trouble by getting a slumping Adam LaRoche to ground into a double play. LaRoche was 4 for 4 with a homer against Affeldt last season.
Brian Wilson finished up in the ninth for his 24th save in 28 opportunities, walking one.
Sanchez pitches Monday in Atlanta, his first start since his no-hitter. ... LaRoche doubled in the fourth, his only hit in 25 at-bats. ... The Giants had nine hits after getting 12 in the first two games. ... Schierholtz also made an excellent defensive play, throwing out Doumit as he tried to stretch a single into a double in the fourth.
California to allow limited fans at Major League Baseball parks
California officials are allowing people to attend Major League Baseball games in limited capacities starting April 1.
Mariners turn nifty triple play
With the bases loaded, the Mariners combine to turn a 5-2-3-2 triple play to get out of a jam.
Ohtani records 5 K's in first spring start
Shohei Ohtani racks up five strikeouts in 1 2/3 innings in his first start of the spring.
Upton blasts a dinger to left as Angels tie A's
Justin Upton cranks a homer to left field, tying the Angels at 2-2 against the Athletics.
Fans collide going for Chris Taylor's grand slam
A fan who caught Michael Taylor's HR earlier tries to grab Chris Taylor's grand slam but he ends up colliding with another fan and dropping the ball.
Fan makes spectacular play on HR ball while Dave Roberts is on FaceTime
While Dave Roberts is being interviewed on FaceTime, Royals' Michael Taylor launches a home run which is caught by a fan in left field.