Agricultural markets rallied on Friday to end the year in style, but sharp losses in wheat, soybeans, cotton, cocoa and sugar at certain points this year weighed on commodities as a whole and left the asset class with its first annual loss in three years.

The 19-commodity Thomson Reuters-Jefferies CRB index ended the year down about 8 percent versus a 17 percent gain in 2010 and a 23 percent rise in 2009. The index, which serves as a global benchmark for commodities, fell despite an annual advance in the price of oil, its main component.

The CRB's biggest decline was in cotton, which fell about 37 percent after record high prices in March boosted output of the fiber which decimated demand.

Natural gas was the second-worst performing component of the CRB, falling 32 percent.

Base metals were also major losers for the year, with copper down about 21 percent and aluminum logging an 18 percent drop.

Metals were affected by fears over the festering euro zone crisis and the dollar's resultant strength against the euro.

Worries about the possibility of an economic slowdown in top metals buyer China, and destocking of a wide variety of metals by that country, also depressed the market. 

"This time last year, analysts would have expected much higher prices than we have now," Stephen Briggs, metals analyst at BNP Paribas, said.   

Gold prices rose for the year, extending their unbeaten run since 2001. The spot price of gold, which tracks trades in bullion, finished the year up 10 percent after huge gains in earlier months mitigated December's sharp sell-off.

U.S. wheat, soybean and corn prices all rose about 1 percent on Friday, boosted by lingering worries about hot, dry weather in Argentina, the world's second largest exporter of corn.

For the year, though, wheat fell 18 percent and soybeans 14 percent, due to losses posted after government estimates of U.S. crop stockpiles exceeded market expectations. Oil posted a third straight year of gains, with London's Brent crude up 13 percent and U.S. crude rising 8
percent. But it was far from a smooth year as prices rose strongly in the first half, tumbled in the third quarter and seesawed over the last three months.

Heating oil was the biggest gainer on the CRB, rising nearly 15 percent. Live cattle posted the second-largest rise of 14 percent.