Brazil's Cosan, the world's largest ethanol and sugar processor, agreed on Monday to merge its ethanol and fuel distribution business with Royal Dutch Shell in a deal worth as much as $12 billion.

The transaction expands Shell's biofuels operations in Brazil, continuing a trend from 2008 when BP took a stake in a big Brazilian biofuels project and announced $1 billion in investments.

The deal would extend Cosan's fuel distribution business in Brazil after the company took over U.S.-based ExxonMobil's Esso unit in 2008 for nearly $1 billion. Cosan last month also agreed to buy a local chain of filling stations called Petrosul for an undisclosed sum.

Cosan said the combined company will have 4,500 filling stations around Brazil, becoming the country's third-largest fuel distributor and helping the company sell directly to consumers a large portion of the ethanol it produces.

Cosan said it has 180 days to discuss the non-binding memorandum of understanding exclusively with Shell International Petroleum Company Ltd.

As part of the transaction, Cosan will transfer its sugar, ethanol, fuels distribution and energy generation business to the merged entity, with assets valued at $4.925 billion and debt of $2.524 billion.

Cosan said Shell will contribute its retail fuels and aviation distribution business and will inject about $1.625 billion into the merged company in up to two years. Cosan will contribute another $300 million in cash over five years.

Cosan and Shell will have the option of buying out each other's stake in the venture after 10 years, with the price of the stakes to be determined at the time of purchase, Cosan said.

(Editing by Todd Benson; Editing by Derek Caney)