PITTSBURGH -- Gerrit Cole won for the first time in nearly a month, and the Pittsburgh Pirates beat San Francisco 4-3 Wednesday for their second straight win over the Giants.
Cole (3-2) beat Tim Lincecum (2-2) for the second time in his 11-month major league career, allowing three runs and seven hits in eight innings with seven strikeouts and a walk. Cole had been 0-2 in four starts since winning his first two outings.
Fill-in closer Mark Melancon worked a perfect ninth for his second save in three chances. Centerfielder Andrew McCutchen made a diving catch of Brandon Crawford's soft liner to left-center for the second out.
Pittsburgh has won four of six after a 1-7 slide, taking two of three in the series. San Francisco had won 10 of 11 before the Pirates' replay-aided walkoff win Tuesday.
Ike Davis had three hits for the Pirates. Brandon Belt hit his ninth home run and drove in all three runs for San Francisco.
Cole, the No. 1 pick in the 2011 amateur draft, won his major league debut at home last June 11 against Lincecum, a two-time NL Cy Young Award winner.
Lincecum (2-2) allowed four runs, eight hits and two walks in four innings Wednesday; opponents are hitting .329 against him.
Belt homered on the first pitch he saw with two outs in the first, then hit a two-run double with two outs in the fifth.
NOTES: Pablo Sandoval was not in the starting lineup after sustaining what Giants manager Bruce Bochy termed a sprain of his hand or thumb during the final play of Tuesday night's game. He pinch hit for Lincecum in the fifth and singled. ... Neil Walker had a second-inning single has has reached safely in all 15 home games he's played against San Francisco ... The Giants headed to Los Angeles for a four-game series against the Dodgers that starts Thursday. San Francisco's starter in the opener, RHP Ryan Vogelsong, has allowed one earned run over 13 innings in his past two starts. ... The Pirates host St. Louis this weekend in a series that includes the first ESPN Sunday night game in PNC Park's 14-year history.