The test was "aimed at strengthening its self defense nuclear deterrent in every way," Pyongyang's official KCNA news agency announced.
A few hours later, the North Koreans launched what appeared to be a short range surface-to-air missile.
Test may be fallout of a succession struggle
South Korean analysts were shocked more by the timing of the test than by the explosion itself, surprised by the speed which Pyongyang had organized it.
Domestic politics, rather than international factors, seem to be driving Pyongyang's behavior, a number of analysts suggest, even though North Korea said last month it was so angry at the UN condemnation of its April 5 missile test that it would resume nuclear activities and withdraw from six-nation talks aimed at denuclearizing the Korean peninsula.
Though outside observers caution that they have no way of knowing what is happening inside the secretive North Korean government as its leader, Kim Jong Il, believed to be battling ill health, two theories have emerged.