North Korea "has ignored the international community's widespread opposition, again carrying out a nuclear test. China's government expresses resolute opposition and strong condemnation toward this", the foreign ministry said in a statement on its website.
The test was North Korea's sixth and was far more powerful than any weapon it has previously detonated.
Pyongyang declared the test of what it called a hydrogen bomb to be a "perfect success".
Beijing is North Korea's main diplomatic ally and economic supporter and is seen as playing a crucial role in efforts to get Pyongyang to curb its weapons programme.