The commitment was weaker than a previous draft of the final communique seen by Reuters, which had included a target to end unabated coal power generation by 2030.
Sources familiar with the discussions said Japan and the United States had both indicated they could not support that date. But the pledge still marked the first commitment from the G7 countries to quit coal-fuelled power. Coal is the most CO2-emitting fossil fuel and use of it needs to plummet if the world is to avoid the worst impacts of climate change.
The war in Ukraine has triggered a scramble among some countries to buy more non-Russian fossil fuels and burn coal to cut their reliance on Russian supplies.
"Replacing fossil fuels from Russia has dominated the political debate and the actions of the government in the past weeks and months," German economy minister Robert Habeck said at a news conference.
"But it must be clear to us that the challenges of our political generation, limiting global warming, won't go away if we just concentrate on the present," he said. "Time is literally running out."
The G7 also agreed to largely decarbonise their power sectors by 2035, and to stop public financing for "unabated" fossil fuel projects abroad by the end of this year, except in limited circumstances. "Unabated" refers to power plants that do not use technology to capture their emissions.
The communique made a commitment to a highly decarbonised road sector by 2030, including significantly increasing the sale, share and uptake of zero emission light duty vehicles.
The G7 also aimed to start reporting publicly next year on how the countries are delivering on a past commitment to end "inefficient" fossil fuel subsidies by 2025.
Habeck would not be drawn on which countries had stood in the way of agreeing a date to phase out coal.
"The real question is whether we can make progress compared with the status quo. I would say, even if the 'better' is the enemy of the 'good' - more is always possible - we have taken a step forward with this conference," he said.
Efforts to find alternatives to Russian natural gas supplies had borne fruit, he added.
"But we must be careful not to be too successful. We don't want to build up a natural gas industry over the next 30 or 40 years that we won't want anymore."
The G7 also pledged to take ambitious action against plastic pollution and to increase national efforts to conserve or protect at least 30 per cent of their own coastal and marine areas by 2030.
"In recent months the clouds have indeed darkened over the international landscape. With (Russian President Vladimir) Putin's illegal and brutal invasion of Ukraine, war has unfortunately returned to Europe," said Alok Sharma, Britain's COP26 climate talks president.