By Julie Wernau 

Sugar prices erased their gains on Thursday after hitting a near-six-week high in early trade, as investors locked in profits.

Raw sugar for October rose to 12.68 cents a pound, the highest intraday price since May 21, after a large company took delivery against the July contract and dented expectations of a global surplus. But the October futures, the most actively traded raw sugar contract on the ICE Futures U.S. exchange, ended down 1.1% at 12.30 cents a pound.

Traders thought the rally was overdone and chose to take profits, said Michael McDougall, head of the Brazil desk at Société Générale in New York. Prices rose as much as 6.1% from Friday's close to Thursday's peak. Also, the holiday-shortened week encouraged some traders to close out of their positions. The U.S. market will be closed Friday for the Independence Day holiday.

The July contract expired Tuesday with 460,930 metric tons of Brazilian raw sugar delivered to Wilmar International Ltd. The Singapore agribusiness group also took delivery of 1.9 million metric tons of sugar against the May contract, a record for the market.

Wilmar bought the equivalent of the entire global supply surplus predicted for the year ending Sept. 30, Commerzbank said in a note. The International Sugar Organization estimates global production will exceed consumption by 2.2 million metric tons this year.

Still, Agrilion Commodity Advisers said Wilmar's sugar refineries in North Africa, India and the Far East should have no difficulty absorbing the tonnage, and there would be plenty of sugar left in the world.

"The bears will argue that the delivered volume was not particularly significant and there is still a sizable prompt surplus with a large volume of Thai [raw sugar] which still need a home," the firm said in a note.

Bell Curve Trading in Freehold, N.J., said in a note that sugar prices ended below a technical trading limit that could signal further gains for the contract in the near term.

In other markets, cotton for December fell 0.2% to end at 67.39 cents a pound, reversing earlier gains that came after U.S. net export sales rose for a third week in a row. In the week ended June 25, net sales of upland cotton, the most common variety grown in the U.S., surged 33% from the previous week to 80,500 bales. Actual shipments of cotton climbed 23% from the previous week to 230,400 bales.

"A lot of these foreign mills are holding off on buying just as much as they can. Some of this might represent 'I've got to have it tomorrow, so I've got to buy it today,'" said Sharon Johnson, introducing broker at Wedbush Securities.

Frozen concentrated orange juice for September rose 1.3% to $1.1815 a pound, and September arabica coffee climbed 0.3% to $1.274 a pound.

Cocoa futures fell 1% for the week, the first such loss after four weekly gains. The September contract ended Thursday up 0.4% at $3,288 a ton.

Write to Julie Wernau at Julie.Wernau@wsj.com

Access Investor Kit for Wilmar International Ltd.

Visit http://www.companyspotlight.com/partner?cp_code=P479&isin=SG1T56930848

Access Investor Kit for Wilmar International Ltd.

Visit http://www.companyspotlight.com/partner?cp_code=P479&isin=US9714331074

Subscribe to WSJ: http://online.wsj.com?mod=djnwires