BERLIN — Germany will spend tens of billions of dollars to end its use of coal power within two decades, if a plan agreed to early Saturday by representatives of the power industry, environmental movement, miners and local interest groups becomes official policy.

The deal, hammered out after more than 20 hours of intense, often fractious negotiating among a 28-member commission appointed last year by Chancellor Angela Merkel, would be one of the most significant energy transformations a nation has yet attempted in the face of climate change.

Thirty countries have already set out proposals to cut their carbon emissions by eliminating coal, the dirtiest and cheapest fossil fuel, including Britain, Canada and Sweden. But none of those plans are of the scale laid out in Germany, an industrial giant that currently relies on coal for almost a third of its energy needs.

The commission’s plan now requires approval from the leaders of four states affected and the federal government.