"We condemn in the strongest terms the nuclear test... which constitutes a flagrant violation of the relevant UN Security Council resolutions," the world's most powerful nations said, in a declaration released Thursday.
"Such a test undermines peace and stability in the region and beyond," said the text, which added condemnation of a North Korean missile launch in April.
"The G8 leadership wanted to send out a single strong message to Pyongyang: you should not continue these provocative actions that pose a threat to regional security," said Kazuo Kodoma, spokesman of Japanese Prime Minister Taro Aso.
"It is time for us to put more pressure on North Korea to appreciate the message," he told reporters.
The world leaders urged Pyongyang to return to "full compliance" with its obligations under the Non-Proliferation Treaty and the International Atomic Energy Agency.
North Korea also test-fired seven ballistic missiles on Saturday in an act of defiance amid US efforts to try to tighten financial sanctions on the country.
The tests, apparently timed to coincide with the US Independence Day holiday, were Pyongyang's biggest salvo of ballistic weaponry since the same day in 2006.
Washington has been pushing for tough enforcement of UN sanctions passed after the May 25 nuclear test and aim to shut down North Korea's nuclear and missile programmes.
Ahead of the statement, US President Barack Obama said it was important to pursue dialogue with Iran and North Korea to dissuade them from acquiring nuclear weapons.
In a meeting with Russian President Dmitry Medvedev early Thursday, Japan's Aso agreed to "continue close cooperation in order to realise the very viable denuclearisation of the Korean Peninsula through negotiations," Kodoma said.
North Korea was also the "number one topic" in bilateral talks with US President Barack Obama on Wednesday, Kodoma said.
"They agreed China has an important role to play vis-a-vis North Korea," he added.
In Thursday's statement, the G8 leaders also voiced "deep concern" over the danger that terrorists might obtain weapons of mass destruction.
They were "determined to continue working together to ensure that terrorists never have access to those weapons and related materials," they said.
The G8 statement praised "new fields of cooperation in areas where the risks of terrorism and proliferation are greatest."