North Korea is to conduct a nuclear test "in the future", the foreign ministry said in a statement.
The move would "bolster" the country's self-defence in the face of US military hostility, official agency KCNA said.
Pyongyang has faced mounting international pressure over its nuclear programme, and in July was condemned by the UN for test-launching missiles.
The news has been condemned by the US, Japan, South Korea and Russia - all members of the six-nation talks.
The US state department said any nuclear test would further isolate the North Korean regime and said the US would work with allies to discourage "such a reckless action".
North Korea gave no time-frame for a test, but correspondents say a successful nuclear trial would signal the end of international negotiations on the North's nuclear ambitions, and threaten a dangerous arms race in East Asia.
Japan's Prime Minister Shinzo Abe said the nuclear test plans were unacceptable and would be responded to "harshly".
South Korea's government went into emergency security talks, while Yang Chang-Seok, a spokesman for the country's unification ministry, warned that any test would have "a decisively negative impact on inter-Korean relations".
Russian Foreign Minister Sergei Lavrov called for restraint, and a diplomatic solution, while UK foreign office officials warned of "serious consequences" to what would be regarded as "a highly provocative act".
North Korea is thought to have developed a handful of warheads but has never before announced it would test one.
The announcement comes as six-nation talks on its nuclear programme have been stalled for a year.
The North has also appeared increasingly angry at sanctions imposed by the US and other countries on North Korean businesses accused of arms sales and illegal activities.
The statement from Pyongyang said it would "in the future conduct a nuclear test under the condition where safety is firmly guaranteed", though it did not state when.
"The US daily increasing threat of a nuclear war and its vicious sanctions and pressure have caused a grave situation on the Korean Peninsula," it said.
COUNTDOWN TO CRISIS
Sept 2005: Hailed as an historic breakthrough, North Korea agrees to give up nuclear activities
Next day, N Korea says it will not scrap its activities unless it gets a civilian nuclear reactor
US imposes financial sanctions on N Korea businesses
July 2006: N Korea test-fires seven missiles
UN Security Council votes to impose sanctions over the tests
Oct 2006: N Korea threatens nuclear test
The ministry went on to say that "under the present situation in which the US moves to isolate and stifle" North Korea, the country "can no longer remain an onlooker to the developments".
The move comes after the UN imposed sanctions on North Korea in July, for test-firing seven missiles including a long-range Taepodong-2 - believed to be capable of reaching Alaska.
The missile tests also prompted South Korea to suspend aid to the North, and correspondents say China had been showing signs of frustration with its old Communist ally.
North Korea claims to have nuclear weapons and to be working on building up its arsenal.
In 2002 it restarted its nuclear reactor at Yongbyon and forced two UN nuclear monitors to leave the country.
It is unclear how far work has progressed at the plant since then.
Washington is not only concerned about the development of such weapons in North Korea, but also wants to curb Pyongyang's capacity to export missile and nuclear technology to other states or organisations.