JAKARTA (Reuters) - Indonesia on Tuesday agreed to let Freeport-McMoRan Inc (>> Freeport-McMoran) keep operating its giant Grasberg copper mine, after the U.S. company said it would cede control of its Indonesian unit, ending years of wrangling.

Freeport has been in talks with Indonesia since late 2009 to work out how to shift to a new permit for Grasberg, the world's second-biggest copper mine, as mandated in a mining law passed that year.

The company said on Tuesday it had made a "major concession and compromise" in selling a 51 percent stake in PT Freeport Indonesia (PT-FI).

The world's biggest publicly listed copper miner said the deal would be structured such that it would retain control over operations and governance of PT-FI.

Shares of Freeport were down 5.6 percent at $14.64 on Tuesday.

The miner will also build a second smelter in Indonesia and plans to invest between $17 billion and $20 billion in Grasberg through 2031.

"It is a short-term positive in that, it allows FCX to export for the foreseeable future," Clarksons Platou Securities analyst Jeremy Sussman said.

"With that said, the up to $20 (billion) spend was more than we were anticipating, and material uncertainty still exists over 'fair market value'."

Top-quality copper mines remain rare and the agreement underlines the mine's importance to Freeport, which produces a quarter of its copper from Grasberg.

It also marks the return of a more muscular stance from a host government, a trend that was common during the commodities boom.

Freeport can "immediately apply" for a 10-year permit extension to mine at Grasberg beyond 2021, said Indonesian Energy and Mineral Resources Minister Ignasius Jonan, and a second extension could be proposed before 2031.

"The mandate of the president, which has been agreed to by Freeport, is that the divestment should reach 51 percent," Jonan told a joint news conference, alongside Freeport Chief Executive Richard Adkerson. "All that is left is to discuss the timing. The price will be negotiated later."

"We are committed to completing the documentation as soon as possible during 2017," Adkerson said in a statement.

Freeport will need to divest a 41.64 percent of its Indonesian unit to a local entity to comply with new local ownership rules introduced in January, on top of the 9.36 percent stake it has already divested to the government.

Freeport has insisted on a "fair market value" for the stake, while the government is seeking a much lower figure and said it should not include unmined copper reserves.

Last year, Freeport offered a 10.64 percent stake in Grasberg for $1.7 billion, valuing the mine at about $16.2 billion. The government counter-offered at $630 million.

"The mechanics, valuation and timing of the 51 percent divestiture are all absolutely critical issues which must be resolved before the dispute can be regarded as finally settled," Jakarta-based foreign legal counsel Bill Sullivan told Reuters.

"BETTER THAN NOTHING"

The agreement also reduces the risk of another stoppage to copper concentrate exports from Grasberg. Global prices for the metal jumped earlier this year when negotiations soured and exports were halted.

"If it wasn't copper, this may have played out differently. But given copper's long-term positive outlook and the billions of dollars already invested by Freeport in Grasberg, they must realize that 49 percent is better than nothing," said James Wilson, mining analyst for Argonaut Stockbroking in Perth.

During Freeport's five decades of operating Grasberg, in Indonesia's eastern province of Papua, there has been frequent friction between the government and the company over revenue sharing and the mine's social and environmental impact.

Labour unrest emerged at Grasberg after Freeport put about 3,000 workers on indefinite leave earlier this year, as a result of the dispute over mining rights.

"We hope that this (agreement) also brings to an end the worker strike," Tri Puspital, a leader at one of the Freeport workers' unions, said on Tuesday.

As part of the latest deal, PT-FI will convert its work contract to a special license, which will give it operating rights through 2041.

Talks between Freeport and the government on Grasberg became more urgent this year as the company's existing 30-year contract is due to expire in 2021 and the government demanded the miner accept the new permit or copper concentrate exports would be stopped.

The new permit would also require Freeport to relinquish arbitration rights and pay new taxes and royalties, among other terms.

Energy Minister Jonan said last week this transition would be a "test case" for Indonesia's mining sector.

NEW RULES

Finance Minister Sri Mulyani Indrawati told the news conference the government was in the process of drafting new rules on taxes and royalties for miners.

Under these rules, the government expects to increase its revenues from Freeport, and the miner could maintain tax rates for "the duration of its operations," Mulyani said.

(Additonal reporting by James Regan in Sydney and Yashaswini Swamynathan in Bengaluru; Writing by Fergus Jensen and Ed Davies; Editing by Christian Schmollinger, Susan Fenton and Maju Samuel)

By Wilda Asmarini and Hidayat Setiaji

Stocks treated in this article : Freeport-McMoran, Rio Tinto Limited, Rio Tinto