The German government and regional leaders have agreed on a plan to phase out coal-fired power stations by 2038, involving compensation of about €40bn (£34bn; $45bn).
The end date for burning brown coal (lignite) - the dirtiest type of coal - could be brought forward to 2035, depending on the progress made.
Germany has more than 250,000 workers in renewable energy sectors - far more than in the coal industry.
Coal is a big driver of global warming.
The €40bn compensation will target four German states which have lignite mines and coal-fired power plants: Saxony-Anhalt, Saxony, North Rhine-Westphalia and Brandenburg.
Much of the money will go into new infrastructure projects for coal-dependent areas and retraining workers for new jobs there.
Mines and utilities will also get compensation for the lost production. The compensation for closing coal-fired power stations in western Germany is set at €2.6bn, and for those in the east at €1.75bn.
A lignite power plant near Halle in eastern Germany
The government will draft a law this month for exiting from coal, which it hopes to get passed by parliament in mid-2020.
Coal currently powers about one-third of Germany's electricity, and more than half of that relies on burning lignite. Germany is the world's biggest lignite producer.
"Germany has embarked on something really big. And I'm sure that we'll manage this," said Finance Minister Olaf Scholz.
Meanwhile, Environment Minister Svenja Schulze said "we're the first country to be finally exiting from nuclear and coal".
In 2017 consumption of lignite in Germany was 44% of the total in the EU, followed by Poland (16%), the Czech Republic and Greece (both 10%), Bulgaria (9%) and Romania (7%), the EU's Eurostat agency reports.
In that year, 359m tonnes of lignite was delivered to power plants in the EU, producing electricity and heat, along with 150m tonnes of hard coal.
Germany aims to generate at least 65% of its electricity from renewables - that is, carbon-neutral sources - by 2030.
The exit from coal consumption is part of the EU's drive to cut greenhouse gas emissions, which contribute to global warming.
A really simple guide to climate change
Most of the 28 EU states aim to become carbon-neutral by 2050 - that is, carbon emissions should be balanced by carbon-reduction measures such as tree-planting. Poland, however, relies heavily on coal and has a temporary exemption.
Under the 2015 Paris Agreement nearly 200 countries agreed on wide-ranging measures to curb emissions, after scientists warned that global temperatures must not rise more than 2C above pre-industrial levels.
Source: BBC