German and American views had differed ahead of the summit
German Chancellor Angela Merkel said the G8 would negotiate within a UN framework to seek a replacement for the Kyoto Protocol by the end of 2009.
No mandatory target was set for the cuts, but Mrs Merkel's preference for a 50% emissions cut by the year 2050 was included in the agreed statement.
Developing nations should also cut emissions, the leaders agreed.
Elsewhere at the summit, US President George W Bush met Russian President Vladimir Putin against a backdrop of disagreements over US plans for missile defence.
Mr Bush said the pair had had a "constructive" meeting, in which Mr Putin suggested using a radar station in Azerbaijan instead of facilities elsewhere in Europe.
Turning the tide
Announcing the climate change deal, Mrs Merkel described it as a "significant and important step forward".
"We agreed... that CO2 emissions must first be stopped and then followed by substantial reductions," the German chancellor said.
According to an extract from the agreed text published on the G8 website, the leaders agreed to take "strong and early" action.
"Taking into account the scientific knowledge as represented in the recent IPCC [Intergovernmental Panel on Climate Change] reports, global greenhouse gas emissions must stop rising, followed by substantial global emission reductions," the text says.
Yvo de Boer, head of the UN's climate change division, quickly welcomed the agreement.
He told the Reuters news agency the deal augured well for a meeting to discuss a post-Kyoto consensus scheduled for Bali in December.
The BBC's diplomatic correspondent Jonathan Marcus, in Heiligendamm, says Mrs Merkel has crafted a compromise while appearing not to have abandoned her principles.
The compromise appears to bring Mr Bush's plan into the wider UN-brokered process - something the US had previously resisted, saying it would not even discuss a post-Kyoto deal.
But changing diplomatic chemistry and an evolving debate on climate change back in the US forced the president to give ground, our correspondent says.
Speaking to reporters in Heiligendamm, UK Prime Minister Tony Blair deflected concerns about the absence of a precise definition of the term "substantial cuts".
"I'm both surprised and very pleased at how far we have come forward in the couple of years since [the 2005 G8 summit at] Gleneagles," he told reporters.
"Now we have an agreement that there will be a climate change deal, it will involve everyone, including the US and China, and it will involve substantial cuts."