By Paul Reynolds
World affairs correspondent, BBC News website
North Korea's nuclear test has thrown efforts to restrain it into further confusion, presenting particular problems for not just the United States but China as well.
North Korea's leadership has much to gain from going nuclear
The effort to halt the spread of nuclear weapons across the world has also taken a blow.
The test represents a failure of both the Chinese (and South Korean) policy of engaging North Korea and the more hardline US approach.
For the Bush administration, the fact that one of the countries described by the president as part of an "axis of evil" has apparently confirmed its membership of the nuclear weapons' club means that, short of military action, there is little it can really do to enforce a change of policy.
Any military action against the North might provoke it into a reckless response.
Its nuclear test does not mean that it now has a useable nuclear bomb.
The device would be too large to be put onto one of its missiles but it has a huge conventional army along the border line with the South.
The United States is calling for sanctions in the Security Council on North Korea under Chapter VII of the UN Charter, and therefore mandatory on member states and enforceable.
The US wants restrictions on trade with the North that might help it develop nuclear weapons, including it seems searches of North Korean ships. It also wants to turn the financial screw on North Korea's dealings abroad.
The resolution is also likely to call on the North to dismantle its nuclear programme and return to the six-party talks, which only last September produced an agreed statement in which the North undertook to give up its nuclear ambitions with the words: "The DPRK committed to abandoning all nuclear weapons and existing nuclear programmes..."
Regional instability fears
But unless China pulls the only real lever on North Korea, its supplies of North Korea's food and oil, the North's defiance will probably continue.
China therefore holds the key. It warned against the North and has now called it "brazen", an unusually strong word.
The test comes as a S Korean is due to be named new UN chief
Whether China acts remains to be seen, however.
It does not want a nuclear-armed North Korea but nor does it wants anything to undermine what it calls the "stability" of the Korean peninsula.
A collapse of the North precipitated by sanctions might produce that "instability" and a flood of refugees or even an eventual take over of the North by the South, in a repetition of what happened in Eastern Europe after communism.
Whether it is now possible to restart the six-party talks and get a negotiation going again must be doubtful in the immediate future.
The North has been angry that the US acted against Far East banks that have laundered its counterfeit dollars. But that could have been an excuse for ignoring the talks, not a real reason.
It has constantly called for bilateral talks with the US but again, nobody really knows if that was a tactic of delay or a real strategy to create conditions for an agreement.
The North Korean leadership has a great deal to gain internally and externally by going nuclear.
Internally it can whip up support under the propaganda of a supposed threat from its enemies and externally it forces others to listen to it.
It has a price to pay in terms of isolation but it cares little for that since it thrives on isolation and sanctions so far have been limited.
The Security Council passed resolution 1695 in July after it tested ballistic missiles, banning trade in missile technology. That has not stopped it.
North Korea might have calculated that since India, Pakistan and Israel have suffered no real penalties, it has little to lose.
And with Iraq in mind, it might have reckoned that a nuclear defence is its best move to head off a possible attack.
That argument however is somewhat contradictory since it would be unlikely to face an attack if it gave up nuclear ambitions.
This happened with Libya but it has not drawn lessons from that example.
As it happens, news of the test came only hours before the Security Council decided on Monday that the South Korean Foreign Minister Ban Ki-moon will be the candidate whose name is sent to the General Assembly for approval as the UN's new secretary-general.
Some have seen more than coincidence in the two events, a not-so-subtle reminder from the North that on the South's big day it cannot be ignored.