Lincecum (6-6) won for the first time since May 27. The 2010 National League Cy Young Award winner gave up three hits and walked two, allowing the Giants to capture the deciding contest in a three-game series.
San Francisco has won two in a row after losing five straight.
Miguel Tejada drove in a San Francisco run with a second-inning groundout and Cody Ross had an RBI single in the eighth to give the Giants a 2-0 lead.
Javier Lopez worked a perfect eighth inning to keep the shutout going, and Brian Wilson allowed a run in the ninth on the way to his 21st save.
Wilson walked the leadoff batter in the ninth and Michael Cuddyer produced a run-scoring double. With the potential tying run on second and nobody out, Wilson retired three straight batters to preserve the victory.
Brian Duensing (4-7) allowed a run on six hits in 6 2/3 innings to suffer the loss.
Notable deaths of 2014 [PHOTOS]