SAN FRANCISCO -- Tim Lincecum ended his final foray into salary arbitration Tuesday by agreeing to a two-year, $40.5 million deal that could propel the right-hander into the open market -- but not necessarily away from the Giants.

The contract's expiration coincides with Lincecum's potential entry into free agency, which might be widely interpreted as a barely concealed farewell to San Francisco. But industry sources said that the contract includes a limited no-trade clause, reflecting Lincecum's desire to remain a Giant.

Lincecum also committed to purchase 25 tickets to each home game at AT&T Park for underprivileged children.

Lincecum expressed his enthusiasm for the settlement in a brief message on his Facebook page: "Thanks for all the support! I look forward to seeing all the fans next week in San Francisco and am excited for the season to begin!"

In theory, the framework for Lincecum's deal was forged last Tuesday, when he and the Giants exchanged proposed salary figures for one-year contracts, a fundamental step in the arbitration process. Lincecum asked for $21.5 million, the largest request ever submitted by a player with less than six years' service time. The Giants countered with $17 million, the richest offer ever made by a ballclub in an arbitration case since the process was implemented in 1974.

Since Lincecum can't become a free agent until after the 2013 season, the only true suspense hinged on the contractual terms he would receive: a one-year deal that would force the parties to endure arbitration next offseason, a two-year agreement that would eliminate arbitration as an issue, or a longer pact that would buy out some of Lincecum's free agency.

The midpoint of the arbitration submissions, $19.25 million, established a base figure for Lincecum's yearly wage. The ceiling was about $5 million higher, given the average annual values of the contracts belonging to baseball's two highest-paid pitchers, the Yankees' CC Sabathia ($24.4 million) and Philadelphia's Cliff Lee ($24 million). The Giants reportedly offered Lincecum a five-year, $100 million package that would have given him considerable security yet left him economically behind the game's elite.

But Lincecum's new deal made him the fourth-highest-paid active pitcher in the Majors in terms of average annual value, ranking behind Sabathia, Lee and the Mets' Johan Santana (approximately $22.9 million).

Lincecum, 27, has remained a premier pitcher while compiling a 69-41 record and a 2.98 ERA in slightly less than five seasons for San Francisco. He won the National League Cy Young Award in each of his first two full seasons. In each of the last four years, he has made the NL All-Star team, exceeded 200 innings pitched and struck out more than 200 batters.

Even last year, when Lincecum posted his first losing mark as a professional (13-14), his 2.74 ERA ranked fifth in the NL. Lincecum's record was largely attributed to his receiving the Major Leagues' lowest run support, which included 10 games in which the Giants scored zero runs while he was on the mound.

"Pure talent-wise, Tim Lincecum is a special, special guy," said MLB Network analyst John Hart, formerly a top executive with Cleveland and Texas.

Officials from the Giants and the Beverly Hills Sports Council, which represents Lincecum, confirmed the deal, which will pay him a $500,000 bonus, $18 million this year and $22 million next year.

Though Lincecum's wages occupy a large percentage of the Giants' $130 million payroll, they gain cost certainty for 2013 by avoiding the possibility of an even more exorbitant raise that he could receive through arbitration.

The Giants also managed to avoid potentially divisive arbitration hearings despite entering the offseason with 13 arbitration-eligible players.

Lincecum will be the second-highest-paid Giant this year, trailing only Barry Zito ($19 million). He'll surpass Zito next season, though the left-hander's salary will rise to $20 million.

With Lincecum signed, the Giants can focus on extending right-hander Matt Cain's contract. Because Cain is eligible for free agency after this season, the urgency to forge a multiyear deal with him actually exceeds the need to reach a similar accord with Lincecum. Cain's slated to earn $15 million this season in the final year of a three-year package.

The Giants will receive some payroll relief that could help them accommodate both Lincecum and Cain. They'll no longer have to pay outfielder Aaron Rowand ($12 million) after this year, and Aubrey Huff ($10 million) will have to perform remarkably to return. San Francisco likely will end its obligation to Zito in 2014 by paying him a $7 million buyout rather than an $18 million club option.