* TSX closes up 117.41 points, or 0.95 percent, at 12,433.53 * Materials sector leads gains amid U.S. budget uncertainty * Canpotex deal boosts potash companies By Allison Martell TORONTO, Dec 31 (Reuters) - Canada's main stock index ended the year up nearly 1 percent on Monday, boosted by the materials sector, as U.S. lawmakers neared a last-minute agreement to avoid the "fiscal cliff" that could push the U.S. economy into recession. Gold rallied in the afternoon after news of a potential deal and held gains as President Barack Obama said a deal to prevent the tax hikes and sharp spending cuts was in sight, but not yet complete. "As always, they leave it to the very last moment, and then something almost invariably emerges, even if it's not the major, game-changing plan that they wanted," said Gavin Graham, president at Graham Investment Strategy. Graham said investors were likely buying gold because of inflation that could follow a resolution of the U.S. budget dispute. Gold is seen as a hedge against inflation. Upbeat manufacturing data out of China also helped the Canadian market. "It's evident now that China is emerging from its slowdown," Graham said. The Chinese data boosted iron ore and copper prices. Teck Resources Ltd, Canada's largest diversified miner, was an influential gainer on the TSX, rising 3.1 percent to C$36.15. The Toronto Stock Exchange's S&P/TSX composite index closed up 117.41 points, or 1.0 percent, at 12,433.53. The index finished 2012 up 4.0 percent, lagging gains in the United States and most major European markets. "If you're a Canadian and you bought the index, you got killed by the commodities this year," said David Baskin, president of Baskin Financial Services. "You got whacked by the gold stocks." Gold miners underperformed in 2012 as soaring operating and development costs cut into profits despite historically high gold prices. Barrick Gold Corp was the most influential gainer on the index on Monday, however, rising 2.8 percent to C$34.82. Goldcorp Inc was 3.2 percent higher, at C$36.57. The heavyweight materials sector closed up 2.6 percent overall. Financial stocks, which have been rising and falling with the perceived chances of a U.S. budget deal in recent weeks, closed up 0.3 percent after a day of choppy trading. Energy stocks rose 1.1 percent as oil prices edged higher on optimism about the U.S. budget talks. Suncor Energy Inc rose 1.5 percent to C$32.71. Canpotex Ltd, the offshore sales agency for Potash Corp of Saskatchewan, Mosaic Co and Agrium Inc , said it struck a six-month agreement to supply a subsidiary of China's Sinofert Holdings Ltd. Potash Corp rose 1.9 percent to C$40.48, and Agrium was up 1.4 percent at C$99.14. The Canadian Imperial Bank of Commerce said it would pay $149.5 million to the estate of Lehman Brothers Holdings Inc to resolve litigation over a collateralized debt tied to the bankruptcy of the former Wall Street bank. Canadian Imperial shares closed down 0.7 percent at C$79.97, and CIBC was the most influential decliner in the index.