Oil rallied on Tuesday on growing optimism that a fiscal deal would be reached soon to avert a U.S. recession in 2013, but most other commodities, particularly agricultural markets, closed lower on poorer demand.

Soybeans slid their most in a month after China, the world's top buyer of the oilseed, unexpectedly canceled a purchase of 300,000 tonnes of U.S. supplies.

Arabica coffee resumed its decline as speculators turned bearish again on a market just rebounded earlier this week from 2-year lows. News of progress in talks to resolve the U.S. budget crisis did little for metals such as copper and gold.

Copper settled down 0.3 percent in New York and 0.5 percent in London, with traders saying any deal to avert the so-called U.S. "fiscal cliff" was probably already priced into the metal. Copper has gained 6 percent since mid-November, while oil and gold prices have largely fallen. Bullion's spot price fell 1.6 percent in Tuesday's session alone, pushing the market to a 3-1/2 month low and bringing losses since mid-November to nearly 3 percent.

Gold sold off even though the dollar slid to a 7-1/2 month low against the euro, which normally would boost gold and other commodities priced in the U.S. currency.

Traders said a budget deal between the White House and Republicans in Congress will probably dilute gold's premium as a safe-haven investment. A deal is needed to avert $600 billion in tax hikes and spending cuts in January -- a scenario that economists warn could tip the United States back into recession.

Top House Republican John Boehner has pledged to press forward on budget negotiations with President Obama, even though many in his party oppose his concession last week to consider higher tax rates on wealthy Americans.

In oil, benchmark Brent's front-month contract in London closed up $1.20, or 1.1 percent, at $108.84 a barrel. U.S. crude in New York gained 73 cents, or 0.8 percent, to settle at $87.93.

Gasoline and heating oil futures in New York both gained more than 1 percent.

"Everything is keying on the 'cliff' hopes, because people are assessing if we're closer to a deal," said Mark Waggoner, president at Excel Futures Inc and an oil market commentator.

The rise in oil and gasoline prices helped edge the Thomson Reuters-Jefferies CRB index -- a commodities indicator largely made up of energy markets - into positive territory. The CRB settled up 0.02 percent although 10 of the 19 markets it tracks ended lower. Silver and soybeans showed the largest loss of about 2 percent each.

Soybeans' front-month January contract in Chicago settled down 30-1/4 cents at $14.66 a bushel after news that China had canceled the U.S. soy cargoes.

The Chinese action signaled that demand for U.S. soybeans were possibly cooling after a robust pace of buying, and ahead of the harvest of the South American soy crop which was to start soon, analysts said.

Aside from the 300,000 tonnes of U.S. supplies dropped by China, the U.S. Department of Agriculture said some 120,000 tonnes of home grown soy to unknown destinations were also canceled.