BEIJING — For decades, North Korea could count on China as a loyal ally despite the erratic behavior of the ruling Kim dynasty. Beijing held its tongue, even as its neighbor engaged in saber rattling, nuclear testing and bombastic threats.

But by this week, things may have gone too far, with North Korea unleashing a tirade in which it deployed some of the most damning insults in its playbook, accusing China of “dancing to the tune of the U.S.” and “styling itself as a big power.”

Chinese observers of relations between the countries were left in disbelief about how rapidly those ties have deteriorated, particularly after Beijing decided to cut off coal imports that provide badly needed currency for the North’s economy.

“At first many people thought it was a fake commentary,” Cheng Xiaohe, associate professor of international studies at Renmin University, said of the tirade against China, published in the North’s state-run news media on Thursday. “It is a big surprise that North Korea has launched such a strong attack against China. I expected an angry reaction — but not this strong.”