BERLIN -- German lawmakers have finalized the country's long-awaited phase-out of coal as an energy source, backing a plan that environmental groups say isn't ambitious enough and free marketeers criticize as a waste of taxpayers' money.

Bills approved by both houses of parliament Friday envision shutting down the last coal-fired power plant by 2038 and spending some 40 billion euros ($45 billion) to help affected regions cope with the transition.

The plan is part of Germany's `energy transition' - an effort to wean Europe's biggest economy off planet-warming fossil fuels and generate all of the country's considerable energy needs from renewable sources. Achieving that goal is made harder than in comparable countries such as France and Britain because of Germany's existing commitment to also phase out nuclear power by the end of 2022.

"The days of coal are numbered in Germany," Environment Minister Svenja Schulze said. "Germany is the first industrialized country that leaves behind both nuclear energy and coal."

Greenpeace and other environmental groups have staged vocal protests against the plan, including by dropping a banner down the front of the Reichstag building Friday. They argue that the government's road map won't reduce Germany's greenhouse gas emissions fast enough to meet the targets set out in the Paris climate accord.

"Germany, the country that burns the greatest amount of lignite coal worldwide, will burden the next generation with 18 more years of carbon dioxide," Greenpeace Germany's executive director Martin Kaiser told The Associated Press.

Kaiser, who was part of a government-appointed expert commission, accused Chancellor Angela Merkel of making a "historic mistake," saying an end date for coal of 2030 would have sent a strong signal for European and global climate policy. Merkel has said she wants Europe to be the first continent to end its greenhouse gas emissions, by 2050.

Germany closed its last black coal mine in 2018, but it continues to import the fuel and extract its own reserves of lignite, a brownish coal that is abundant in the west and east of the country. Officials warn that the loss of mining jobs could hurt those economically fragile regions, though efforts are already under way to turn the vast lignite mines into nature reserves and lakeside resorts.

Schulze, the environment minister, said there would be regular government reviews to examine whether the end date for coal can be brought forward. She noted that by the end of 2022, eight of the country's most polluting coal-fired plants will have already been closed.

Environmentalists have also criticized the large sums being offered to coal companies to shut down their plants, a complaint shared by libertarians such as Germany's opposition Free Democratic Party.

Katja Suding, a leading FDP lawmaker, said the government should have opted to expand existing emissions trading systems that put a price on carbon, thereby encouraging operators to shut down unprofitable coal plants.

"You just have to make it so expensive that it's not profitable anymore to turn coal into electricity," she said.

This week, utility companies in Spain shut down seven of the country's 15 coal-fired power plants, saying they couldn't be operated at profit without government subsidies.

But the head of Germany's main miners' union, Michael Vassiliadis, welcomed the decision, calling it a "historic milestone." He urged the government to focus next on an expansion of renewable energy generation and the use of hydrogen as a clean alternative for storing and transporting energy in the future.

------

David Rising contributed to this report.