Tim Lincecum has agreed to terms on a two-year deal with the San Francisco Giants through the 2015 season, keeping the two-time Cy Young Award winner off the free-agent market.