The decision by the centre-right coalition, which was prompted by the Japanese crisis, was announced in the early hours of Monday by Environment Minister Norbert Roettgen, who said it was "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.
Germany has 17 nuclear reactors on its territory, eight of which are currently off the electricity grid while they are subject to a safety review.
Monday's decision made Germany the first major industrial power to announce plans to give up atomic energy entirely.
The decision means that the country will have to find the 22 per cent of its electricity needs currently covered by nuclear reactors from another source.
Roettgen said 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.
He said the government had largely followed the recommendations of an "ethics panel" appointed by Merkel after the Fukushima disaster.