North Korea has lashed out against its main ally, China, over criticism of its nuclear weapons programme, accusing "ignorant politicians and media persons" of undermining decades of close relations to side with the United States.

With tensions rising on the Korean Peninsula as a US aircraft carrier strike group conducts war games with South Korea's navy, North Korea's state media took its Chinese counterpart to task on Wednesday over "absurd and reckless remarks" that are "dancing to the tune of the US".

"The DPRK will never beg for the maintenance of friendship with China," the commentary on the Korean Central News Agency (KCNA) said, using the acronym for the Democratic People's Republic of Korea.

The report chided China for its "insincerity and betrayal on the part of its partner".

China's state-run Global Times newspaper retorted on Thursday that the nuclear-armed North was in the grip of "some form of irrational logic" over its weapons programmes.

READ MORE: North Korea: 'US has now gone seriously mad' 

THAAD goes live amid growing South Korea anger

Beijing and Pyongyang have a relationship forged in the blood of the 1950-53 Korean War, and the Asian giant remains its neighbour's main provider of aid and trade.    

But ties have begun to fray in recent years with China increasingly exasperated by North Korea's nuclear tests and missile launches, fearful of a regional crisis.

China regularly calls for all parties to avoid raising tensions - remarks that can apply to both Washington and Pyongyang.

In February it announced the suspension of coal imports from the North for the rest of the year, a crucial foreign currency earner for its neighbour.    

China's state-run media has called for harsher sanctions against North Korea in the event of a new nuclear test, urged Pyongyang to "avoid making mistakes at this time", and spoken of the need for Pyongyang to abandon its nuclear programme.

But KCNA rebuked those suggestions in a rare outburst against its longtime ally.

"Ignorant politicians and media persons of China … are advised to clearly understand the essence of history before opening their mouth," the commentary said.

"China should no longer try to test the limits of the DPRK's patience … China had better ponder over the grave consequences to be entailed by its reckless act of chopping down the pillar of the DPRK-China relations."

OPINION: Will China intervene in North Korea?

Ongoing joint naval exercises between the US and South Korea have triggered the threat of nuclear war from North Korea.  

US President Donald Trump deployed the USS Carl Vinson aircraft carrier to the Korean Peninsula last month. North Korea has threatened to sink the US armada.

Tensions in the Asia-Pacific have been running high for weeks with signs that North Korea might be preparing a sixth nuclear weapon test - and with Washington refusing to rule out a military attack in response.

China welcomes US 'path of dialogue' with North Korea - Inside Story

Source: Al Jazeera and news agencies