Germany's exit from the coal industry marks the second major upheaval for RWE in as many years following the breakup of the .company's former subsidiary Innogy with peer E.ON.
It also accelerates RWE's transformation into a pure renewables group, which - along with its low valuation - could turn it into a takeover target, Goldman Sachs said last week.
RWE said it would receive 2.6 billion euros ($2.9 billion) in compensation from the government over 15 years to soften the blow to its business.
However, this was less than the 3.5 billion euro (2.98 billion pounds) hit it estimated it would take, even excluding the expected loss of profits, it added.
"RWE stretches to the limits of what is possible," Chief Executive Rolf Martin Schmitz told journalists on a call. "And we will bear the majority of the burden the German government demands for the coal phase-out."
After months of wrangling, the German government early on Thursday agreed a compensation plan with energy companies, affected regions and workers to pay for the accelerated shutdown of coal-fired power stations by 2038.
RWE said it expected special writedowns of half a billion euros on power plants and open-cast mines as a result of the agreement. About 350 million euros will be set aside for personnel measures.
Shares in the group were 2% higher at 1508 GMT, the second-biggest gainers among German blue-chips, having earlier touched their highest since Sept. 25, 2014 as traders welcomed the clarity after months of wrangling.
"RWE's agreement with the German government lifts an important overhang," Bernstein analysts wrote.
"Some investors were cautious on whether RWE would be able to receive adequate compensation for early mine closures, given the past track record of negotiations with the government."
Schmitz denied speculation that RWE may now seek to sell its coal assets, adding the firm, which is also Europe's third-largest renewable group after Iberdrola and Enel, would stand by its employees.
"There are no such considerations and no talks on the matter," Schmitz said.
The company has in the past denied claims that its coal-fired plants are loss-making, saying it would not run them unless they generated cash.
Dave Jones, European electricity analyst at Sandbag, a non-profit think-tank, said that it had been clear that coal would have to be phased out even before the Paris Agreement to combat climate change was struck in 2015.
"It's a pertinent lesson for all other countries: deal with coal now, and save yourself a big bill in the future," he said.
(GRAPHIC: RWE vs European rivals - https://fingfx.thomsonreuters.com/gfx/mkt/13/1135/1126/rwe.png)
By Christoph Steitz, Vera Eckert and Matthew Green