The deal means Freeport is granting a 51% ownership in the mine to Indonesia and has committed to build smelters in the country. In return, the US miner will be allowed to keep the mine open until 2041.

The tentative agreement is meant to put an end to mounting public rage over foreign ownership of Indonesia’s biggest copper asset. It could also bring closure to years of disagreements between the Phoenix, Arizona-based company and the country’s government, which curbed output at the mine, impacting metals prices worldwide.

The deal is considered a victory for President Joko Widodo, who faces re-election in 2019 and who has insisted that mining companies must divest majority stakes in order to continue operating in the country.

“The result of this negotiation is in accordance with the instructions of President Joko Widodo to prioritize the national interest, the interests of the people of Papua, the sovereignty of the state in the management of natural resources, and keep the investment climate remains conducive,” the Ministry of Energy and Mineral Resources said in a statement.

The two parties still have to negotiate the details of the agreement, including what the Indonesian government might have to pay for the stake in Grasberg, responsible for more than a quarter of Freeport’s total output.

Last year, the iconic mine — the world’s largest gold mine and second-largest copper operation — generated more than 500,000 tonnes of copper and over 1 million ounces of gold.

Freeport’s stock was down almost 4% to $14.91 in New York at 9:45AM local time. Year-to-date, shares are up more than 13%, compared with a 23% increase in the benchmark copper prices on the London Metals Exchange.