Environment Minister Norbert Roettgen announced the decision by the centre-right coalition, which was prompted by the crisis at Japan's Fukushima plant, in the early hours of Monday morning, describing it as "irreversible".
"After long consultations, there is now an agreement by the coalition to end nuclear energy," he told reporters after seven hours of negotiations into the small hours at Chancellor Angela Merkel's offices.
"This decision is consistent, decisive and clear."
Germany has 17 nuclear reactors on its territory, eight of which are currently off the electricity grid.
Seven of those offline are the country's oldest nuclear reactors, which the federal government shut down for three months pending a safety probe after the Japanese atomic emergency at Fukushima that began in March.
The eighth is the Kruemmel plant, in northern Germany, which has been mothballed for years because of technical problems.
Monday's decision made Germany the first major industrial power to announce plans to give up atomic energy entirely.
But it also means that the country will have to find the 22% of its electricity needs currently covered by nuclear reactors from another source.
Roettgen insisted there was no danger of blackouts.
"We assure that the electricity supply will be ensured at all times and for all users," he pledged, but did not provide details.
Already on Friday, the environment ministers from all 16 German regional states had called for the temporary order on the seven plants to be made permanent.
Roettgen said on Monday that none of the eight reactors offline would be reactivated. Six further reactors would be shut down by the end of 2021 and the three most modern would cease operation by the end of 2022.
Monday's decision is effectively a return to the timetable set by the previous Social Democrat-Green coalition government a decade ago.
And it is a humbling U-turn for Merkel, who at the end of 2010 decided to extend the lifetime of Germany's 17 reactors by an average of 12 years, which would have kept them open until the mid-2030s.
That decision was unpopular in Germany even before the earthquake and tsunami in March that severely damaged the Fukushima nuclear facility in Japan, prompting Merkel's review of nuclear policy.
Her zig-zagging on what has been a highly emotive issue in the country since the 1970s has cost her since at the ballot box.
Merkel herself has blamed the Fukushima nuclear disaster for recent defeats in state elections.
In the latest, on May 23, the anti-nuclear Greens pushed her conservative party into third place in a vote in the northern state of Bremen, the first time they had scored more votes than the conservatives in a regional or federal election.
The late-night wrangling in Merkel's fractious team saw the pro-business Free Democrats (FDP) arguing against a fixed end date for nuclear power, and to maintain two reserve reactors in case of energy shortages.
FDP sources said there would be a contingency plan with one reactor but did not provide details.
Meanwhile the Christian Social Union, the Bavarian sister party of Merkel's Christian Democrats, fought for an exit within 10 years.
Some coalition members had called for a built-in review clause which could have seen the decision revisited, but this was thrown out in the final round of negotiations.
Roettgen said the government had largely followed the recommendations of an "ethics panel" appointed by Merkel after the Fukushima disaster, which called for an end to nuclear power in Germany within a decade.